mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-10 02:47:50 +00:00
Optimize isPlainObject use in _.clone.
Former-commit-id: 7bb48bc5f9276c730f947b6e75b6fba4588f17c1
This commit is contained in:
11
lodash.js
11
lodash.js
@@ -746,12 +746,15 @@
|
|||||||
*
|
*
|
||||||
* @private
|
* @private
|
||||||
* @param {Mixed} value The value to check.
|
* @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
|
// avoid non-objects and false positives for `arguments` objects
|
||||||
var result = false;
|
var result = false;
|
||||||
if (!(value && typeof value == 'object') || isArguments(value)) {
|
if (!(value && typeof value == 'object') || (!skipArgsCheck && isArguments(value))) {
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
// IE < 9 presents DOM nodes as `Object` objects except they have `toString`
|
// IE < 9 presents DOM nodes as `Object` objects except they have `toString`
|
||||||
@@ -1015,7 +1018,7 @@
|
|||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
var isArr = className == arrayClass;
|
var isArr = className == arrayClass;
|
||||||
isObj = isArr || (className == objectClass ? isPlainObject(value) : isObj);
|
isObj = isArr || (className == objectClass ? isPlainObject(value, true) : isObj);
|
||||||
}
|
}
|
||||||
// shallow clone
|
// shallow clone
|
||||||
if (!isObj || !deep) {
|
if (!isObj || !deep) {
|
||||||
|
|||||||
Reference in New Issue
Block a user