EDIT: Fixed my example to demonstrate the behavior.
I wanted the details
property of AbstractParent to be what I would call an "instance property" but it's acting more like a "static property". I realize these terms are not appropriate for javascript, so why when I create a new child class does it not get its own unique AbstractParent prototype? Why do they share the same one?
In the code below I expect an empty alert, but instead I get 'new details'
var AbstractParent = Backbone.Model.extend({
details: [],
addDetail: function(detail) {
this.details.push(detail);
},
getDetails: function() {
var rtn = '';
for(var i=0;i<this.details.length;i++) {
rtn += this.details[i];
}
return rtn;
}
});
var Child = AbstractParent.extend({});
var ch1 = new Child;
ch1.addDetail("new details");
var ch2 = new Child;
alert(ch2.getDetails()); // => 'new details'
This seems to only work this way when details
is an array. If it is a string or an object then it is not shared by ch1
and ch2
.