From c6208db025b25ce563fe7e7ea9736fe8b90cc6bb Mon Sep 17 00:00:00 2001 From: Graeme Date: Sat, 13 Dec 2014 11:47:03 -0500 Subject: [PATCH 1/2] Refactor Base._set --- src/core/Base.js | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/core/Base.js b/src/core/Base.js index 208eacca..95fff0b3 100644 --- a/src/core/Base.js +++ b/src/core/Base.js @@ -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; From 4837df715f0f3ed0374f48586d8797c3ffd1e9f2 Mon Sep 17 00:00:00 2001 From: Graeme Date: Sat, 13 Dec 2014 12:05:42 -0500 Subject: [PATCH 2/2] Use keys loop in serialize --- src/core/Base.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/core/Base.js b/src/core/Base.js index 95fff0b3..a8e29cd5 100644 --- a/src/core/Base.js +++ b/src/core/Base.js @@ -369,10 +369,10 @@ Base.inject(/** @lends Base# */{ res._compact = true; } else if (Base.isPlainObject(obj)) { res = {}; - for (var i in obj) - if (obj.hasOwnProperty(i)) - res[i] = Base.serialize(obj[i], options, compact, - dictionary); + for (var keys = Object.keys(obj), i = 0; i < keys.length; i++) { + var key = keys[i]; + res[key] = Base.serialize(obj[key], options, compact, dictionary); + } } else if (typeof obj === 'number') { res = options.formatter.number(obj, options.precision); } else {