I’ve been banging my head on this one for the last two days. For some reason backbone is sharing parent instance data across inherited child models. Heres an example:
var Base = Backbone.Model.extend({
index : []
});
var Group = Base.extend({
initialize : function() {
this.index.push('from group');
}
});
var User = Base.extend({
initialize : function() {
this.index.push('from user');
}
});
var user = new User();
console.log(user.index); // ['from user']
var group = new Group();
console.log(group.index) // ['from user', 'from group']
What I’m looking for is:
console.log(user.index); // ['from user']
console.log(group.index) // ['from group']
Any insights?
Thanks!
Matt
What you are experiencing is essentially a byproduct of the way JS passes objects (or arrays) by reference and not by value. If you want index to be different for User and Group, simply instantiate it as an array in your initialize function.