Support override of non-function properties? #1

merged 2 commits into from Sep 22, 2012


None yet
2 participants

teleological commented Sep 22, 2012

I ran into a problem with Cocktail where a mixin which defined url() was applied to a Backbone Collection that defined a url as a string: Cocktail raised an exception when trying to apply() the colliding string. This patch makes it possible to override non-function properties in the prototype with mixin functions. If mixin functions collide but don't return a defined value, the prototype property value is returned. The behavior of ignoring non-function properties in mixins (excepting "events") is unchanged. Thanks for Cocktail!

teleological added some commits Sep 22, 2012

@teleological teleological Support mixin override of non-function properties 638964b
@teleological teleological Add additional spec
* Case where mixin function returning undefined overrides non-function

onsi merged commit 0b78f0b into onsi:master Sep 22, 2012


onsi commented Sep 22, 2012

Thanks for the pull request. The feature and code both make sense to me :)

As a related aside, I tend to shy away from defining non-function properties on Backbone classes and prefer to set them up in initialize instead. I do this mainly because properties defined on the class are shared across instances. So if one instance attempts to mutate a property, all other instances will pick up the change! Putting the property in the constructor ensure that each instance holds its own copy of the property.

Obviously, this is less relevant for strings (which are immutable) but it's quite relevant for dictionaries and arrays!


teleological commented Sep 24, 2012

Good point! Thanks again!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment