JavaScript inheritance is a prototype - objects can refer directly to the properties above in the prototype chain.
In your example, one and two share a common prototype and do not provide their own values ββfor myProperty , so both of them refer directly to Model.protoype.myProperty .
You should create a new myProperty array for each model you create. Model.initialize is an idiomatic place for this kind of initialization - redefining constructor unnecessarily complicated.
var Model = Backbone.Model.extend({ initialize: function() { this.myProperty = []; } });
Alternatively, you can make myProperty as a model attribute:
var Model = Backbone.Model.extend({ defaults: function() { return { myProperty: [] } } });
It is important to note that defaults is a function - if you were to use a simple object, you would encounter the same problem with a shared link.
joews source share