Skip to content

Instantly share code, notes, and snippets.

@tivac
Created June 22, 2012 20:58
Show Gist options
  • Save tivac/2975132 to your computer and use it in GitHub Desktop.
Save tivac/2975132 to your computer and use it in GitHub Desktop.
More powerful Model.reset()
ResetExtension = function(){};
ResetExtension.prototype = {
reset : function(name, options) {
var self = this,
attributes = {};
//allow old-style string name/string name + options/just options
if(Y.Lang.isString(name)) {
attributes[name] = self._state.get(name, "initValue");
} else if(Y.Lang.isObject(name)) {
options = name;
}
if(options && options.attributes) {
attributes = Y.merge(attributes, options.attributes);
delete options.attributes;
}
Y.Object.each(self._state.data, function(value, key) {
if(!Y.Object.owns(attributes, key)) {
attributes[key] = self._state.get(key, "initValue");
}
});
return self.setAttrs(attributes, options);
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment