From f9f08ba54fbd02d90026d4aef84ec31aa3de7cc4 Mon Sep 17 00:00:00 2001 From: John-David Dalton Date: Fri, 17 Aug 2012 08:16:31 -0700 Subject: [PATCH] Optimize `isPlainObject` use in `_.clone`. Former-commit-id: 7bb48bc5f9276c730f947b6e75b6fba4588f17c1 --- lodash.js | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/lodash.js b/lodash.js index 988141a95..598122972 100644 --- a/lodash.js +++ b/lodash.js @@ -746,12 +746,15 @@ * * @private * @param {Mixed} value The value to check. - * @returns {Boolean} Returns `true` if the `value` is a plain `Object` object, else `false`. + * @param {Boolean} [skipArgsCheck=false] Internally used to skip checks for + * `arguments` objects. + * @returns {Boolean} Returns `true` if the `value` is a plain `Object` object, + * else `false`. */ - function isPlainObject(value) { + function isPlainObject(value, skipArgsCheck) { // avoid non-objects and false positives for `arguments` objects var result = false; - if (!(value && typeof value == 'object') || isArguments(value)) { + if (!(value && typeof value == 'object') || (!skipArgsCheck && isArguments(value))) { return result; } // IE < 9 presents DOM nodes as `Object` objects except they have `toString` @@ -1015,7 +1018,7 @@ return value; } var isArr = className == arrayClass; - isObj = isArr || (className == objectClass ? isPlainObject(value) : isObj); + isObj = isArr || (className == objectClass ? isPlainObject(value, true) : isObj); } // shallow clone if (!isObj || !deep) {