Backbone inheritance - deep copying
Posted
by
Ed .
on Stack Overflow
See other posts from Stack Overflow
or by Ed .
Published on 2012-10-01T10:57:56Z
Indexed on
2012/10/16
11:01 UTC
Read the original article
Hit count: 174
I've seen this question regarding inheritance in Backbone: Backbone.js view inheritance. Useful but doesn't answer my question.
The problem I'm experiencing is this:
Say I have a class Panel
(model in this example);
var Panel = Backbone.Model.extend({
defaults : {
name : 'my-panel'
}
});
And then an AdvancedPanel
;
var AdvancedPanel = Panel.extend({
defaults : {
label : 'Click to edit'
}
});
The following doesn't work:
var advancedPanel = new AdvancedPanel();
alert(advancedPanel.get('name')); // Undefined :(
JSFiddle here: http://jsfiddle.net/hWmnb/
I guess I can see that I can achieve this myself through some custom extend function that creates a deep copy of the prototype, but this seems like a common thing that people might want from Backbone inheritance, is there a standard way of doing it?
© Stack Overflow or respective owner