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!
Support mixin override of non-function properties
Add additional spec
* Case where mixin function returning undefined overrides non-function
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!
Good point! Thanks again!