I have a FormView which handles such events as save and cancel. I also have an AjaxFormView that handles save, cancel and get form by ajax. I have an AssetFormView that handles save, cancel, get by ajax, delete, and print.
So on and so forth. there is considerable repitition.
I found a post this post http://kalimotxocoding.blogspot.com/2011/03/playing-with-backbonejs-views.html
where he shows you can extend views. However, I’m finding that when i have multiple versions of views on the page there are properties cross pollinating. Is there no built in way to inherit views in backbone, that is safe?
Thanks,
Raif
* hmmm well, this stuff is pretty thick and my current cross pollination issue may be ( probably is ) the result of some error on my part, but the question still stands, is there not and would it not be an important feature to have, some way to inherit views?
I’d like to see what you mean when you say that your properties are cross-pollenating.
The
View.extendmechanism works quite well. Do be aware, though, that you are extending one prototype with new functions. With prototypical inheritance, the prototype shares it’s objects with the new instances.I am guessing that when you say that your properties are “cross-pollenating”, you are actually doing something like this:
Since the objects are shared, every instance of
baseModelends up having the same object forfoo, giving the feeling of cross-pollination.If instead, you define your defaults as a function, then each instance will get it’s own copy of the
fooobject and your cross-pollination goes away.Of course, without code, we can’t be certain to what your problem is. Just know that this mechanism has been well-used among the community without trouble. It is safe. You just need to understand what is going on.