Last active
September 17, 2015 17:37
-
-
Save moos/34645e0468578c416469 to your computer and use it in GitHub Desktop.
Backbone.Model.prototype.reset(attrs, options)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* add reset() to Backbone.Model. Note 'id' attribute is kept. | |
* | |
* Unlike Backbone.Collection's native reset, no 'reset' event is fired. | |
* | |
* @param attrs {object} - hash of any new attributes to set, otherwise set to defaults | |
* @param options {object} - options to pass to set() | |
*/ | |
Backbone.Model.prototype.reset = function(attrs, options) { | |
var opts = _.defaults(options || {}, {silent: true}), | |
idkey = this.idAttribute, | |
allAttrs = _.defaults(attrs || {}, this.defaults); | |
// keep old id if none was specified | |
if (!(idkey in allAttrs) && idkey in this.attributes) allAttrs[idkey] = this.attributes[idkey]; | |
this.clear(opts).set(allAttrs, opts); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment