Yes, because bad2.b
and bad1.b
is the same object, coming from their shared prototype. To avoid this, you should assign b
a value in the initialize
method.
var myBadExtension = myObj.extend({
initialize: function() {
this.b = {
c: "hello"
};
}
});
It won't matter if a property is primitive (IOW not an object or an array), but I think it's more common to initialize primitives in the same way.
Given you are not using backbone's built-in classes, this might have a better chance of working.
var myBadExtension = myObj.extend({
constructor: function() {
myObj.apply(this, arguments);
this.b = {
c: "hello"
};
}
});