The problem is that Inventory.prototype.defaults
and Extended.prototype.defaults
has the same reference, because you have not override the reference.
So you can do this in 2 ways, maybe more but i only found this 2:
Edit: The first example is incorrect (see comments); please refer to the second.
var ExtendedInventory = Inventory.extend({
defaults: {
rabit:25
}
});
_.extend(ExtendedInventory.prototype.defaults, Inventory.prototype.defaults);
or
var ExtendedInventory = Inventory.extend({
defaults: _.extend({},Inventory.prototype.defaults,
{rabit:25}
)
});
I think the first looks cleaner.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…