Reputation: 119
I have a backbone model which I don't have access to edit.So i want to modify the method of it, so that other methods functionality wont affect.
ShoppingDetail = Backbone.Model.extend({
className: 'CartID',
fetch: function() {},
checkForChanges: function() {},
newCoupon: function() {},
saveAndallow: function() {}
});
shoppingDetailModel = new ShoppingDetail();
shoppingCartView = new ShoppingCartView({
model: shoppingDetailModel
});
So i want to override saveAndallow method of the model.How could i do that without affecting other methods of that model
Upvotes: 2
Views: 587
Reputation: 165
Why don't you create a new Model which will extend your ShoppingDetail Model ?
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
});
So now, when you call any method, it will first check if it is available in NewShoppingDetail, if not available, then it will check ShoppingDetail.
Upvotes: 2