Refactor Base._set

This commit is contained in:
Graeme 2014-12-13 11:47:03 -05:00
parent f193acf31b
commit c6208db025

View file

@ -72,18 +72,18 @@ Base.inject(/** @lends Base# */{
* @return {Boolean} {@true if the object is a plain object}
*/
_set: function(props, exclude, dontCheck) {
if (props && (dontCheck || Base.isPlainObject(props))) {
if (dontCheck || Base.isPlainObject(props)) {
// If props is a filtering object, we need to execute hasOwnProperty
// on the original object (it's parent / prototype). See _filtered
// inheritance trick in the argument reading code.
var orig = props._filtering || props;
for (var key in orig) {
if (orig.hasOwnProperty(key) && !(exclude && exclude[key])) {
var value = props[key];
var keys = Object.keys(props._filtering || props);
for (var i = 0; i < keys.length; i++) {
var key = keys[i];
if (!(exclude && exclude[key])) {
// Due to the _filtered inheritance trick, undefined is used
// to mask already consumed named arguments.
if (value !== undefined)
this[key] = value;
if (props[key] !== undefined)
this[key] = props[key];
}
}
return true;