我有一个骨干模型,我无权访问edit.So我想修改它的方法,以便其他方法功能不会影响。
ShoppingDetail = Backbone.Model.extend({
className: 'CartID',
fetch: function() {},
checkForChanges: function() {},
newCoupon: function() {},
saveAndallow: function() {}
});
shoppingDetailModel = new ShoppingDetail();
shoppingCartView = new ShoppingCartView({
model: shoppingDetailModel
});
所以我想覆盖模型的saveAndallow方法。我怎么能这样做而不影响该模型的其他方法
答案 0 :(得分:2)
为什么不创建一个扩展ShoppingDetail模型的新模型?
ShoppingDetail = Backbone.Model.extend({
className: 'CartID',
fetch: function() {},
checkForChanges : function() {},
newCoupon: function(){},
saveAndallow: function(){}
});
NewShoppingDetail = ShoppingDetail.extend({
saveAndallow: function(){};
});
shoppingDetailModel = new NewShoppingDetail();
shoppingCartView = new ShoppingCartView({
model : shoppingDetailModel
});
现在,当您调用任何方法时,它将首先检查它是否在NewShoppingDetail中可用,如果不可用,则它将检查ShoppingDetail。