3 ms·
Thanks, I was honestly confused, not trying to nit pick. --- Anyone know the best way to make it so set defaults to {validate:true}? Override Backbone.Model.
by hueyp 14y ago
Thanks, I was honestly confused, not trying to nit pick.
---
Anyone know the best way to make it so set defaults to {validate:true}? Override Backbone.Model.set, extend options and call original?
- philfreo 14y agoSure (though I recommend just updating your code instead...) Only reason it's tricky is because there are two different forms of attributes that can be passed to set. Something like this should work: var oldSet = Backbone.Model.prototype.set; Backbone.Model.prototype.set = function(key, val, options) { if (key == null) return this; if (typeof key === 'object') { options = val; } options || (options = {}); options.validate = true; oldSet.call(this, key, val, options); };