Created
June 22, 2012 20:58
-
-
Save tivac/2975132 to your computer and use it in GitHub Desktop.
More powerful Model.reset()
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
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