-
-
Notifications
You must be signed in to change notification settings - Fork 29
Class inheritance is overkill #3
Comments
We originally wrote this before Backbone's |
yep NP. In fact ... recipeswithbackbone/recipeswithbackbone.github.com#23 :-D |
I tried using a fix similar to the change @domchristie used, but it means that you need to manually apply the |
I think the inheritance pattern used in I came across a similar issue when trying to extend the
Relating this to
To fix this, I used some code from the Backbone source to 'do' inheritance. It's very similar to currently exists, but just adds the parent's prototype to the child's prototype chain:
And with this pattern:
Now this may not be as important as with a |
@domchristie interesting stuff. I haven't run into a situation where that's mattered before, but I'd take a pull request to correct the constructor chain. |
in here: https://github.com/thoughtbot/backbone-support/blob/master/lib/assets/javascripts/backbone-support/swapping_router.js
You are using _'s
extend
which requires you to extend the prototype as well, but Backbone JS has its own extend method:http://documentcloud.github.com/backbone/#Model-extend
It is self-propagating so objects that
extend
a method with thisextend
method get their ownextend
method as well:https://github.com/documentcloud/backbone/blob/master/backbone.js#L992
And also inherits the prototype for you:
https://github.com/documentcloud/backbone/blob/master/backbone.js#L1081
When I started working with backbone, it didn't work like this, so I ended up doing something similar to what you guys have, but since they improved
extend
it's much easier to subclass.Unless of course there's something I'm missing here about the behavior of
extend
:-)Thanks for sharing your code.
-@ngauthier
The text was updated successfully, but these errors were encountered: