Backbone inheritance - deep copying
- by Ed .
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?