mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-12 11:57:49 +00:00
Ensure a customer function works on deep cloned objects.
This commit is contained in:
26
lodash.js
26
lodash.js
@@ -1485,12 +1485,17 @@
|
|||||||
* @param {*} value The value to clone.
|
* @param {*} value The value to clone.
|
||||||
* @param {boolean} [isDeep=false] Specify a deep clone.
|
* @param {boolean} [isDeep=false] Specify a deep clone.
|
||||||
* @param {Function} [customizer] The function to customize cloning values.
|
* @param {Function} [customizer] The function to customize cloning values.
|
||||||
|
* @param {string} [key] The key of `value`.
|
||||||
|
* @param {Object} [object] The object `value` belongs to.
|
||||||
* @param {Array} [stackA=[]] Tracks traversed source objects.
|
* @param {Array} [stackA=[]] Tracks traversed source objects.
|
||||||
* @param {Array} [stackB=[]] Associates clones with source counterparts.
|
* @param {Array} [stackB=[]] Associates clones with source counterparts.
|
||||||
* @returns {*} Returns the cloned value.
|
* @returns {*} Returns the cloned value.
|
||||||
*/
|
*/
|
||||||
function baseClone(value, isDeep, customizer, stackA, stackB) {
|
function baseClone(value, isDeep, customizer, key, object, stackA, stackB) {
|
||||||
var result = customizer ? customizer(value) : undefined;
|
var result;
|
||||||
|
if (customizer) {
|
||||||
|
result = object ? customizer(value, key, object) : customizer(value);
|
||||||
|
}
|
||||||
if (typeof result != 'undefined') {
|
if (typeof result != 'undefined') {
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
@@ -1524,15 +1529,8 @@
|
|||||||
stackB.push(result);
|
stackB.push(result);
|
||||||
|
|
||||||
// recursively populate clone (susceptible to call stack limits)
|
// recursively populate clone (susceptible to call stack limits)
|
||||||
(isArr ? arrayEach : baseForOwn)(value, function(val, key) {
|
(isArr ? arrayEach : baseForOwn)(value, function(subValue, key) {
|
||||||
var computed = customizer ? customizer(val, key) : undefined,
|
result[key] = baseClone(subValue, isDeep, customizer, key, value, stackA, stackB);
|
||||||
useComputed = typeof computed != 'undefined',
|
|
||||||
isReflexive = useComputed && computed === computed;
|
|
||||||
|
|
||||||
if (useComputed && (isReflexive ? val === computed : val !== val)) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
result[key] = useComputed ? computed : baseClone(val, isDeep, null, stackA, stackB);
|
|
||||||
});
|
});
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
@@ -3139,7 +3137,7 @@
|
|||||||
// enumerable properties.
|
// enumerable properties.
|
||||||
var result;
|
var result;
|
||||||
if (support.ownLast) {
|
if (support.ownLast) {
|
||||||
baseForIn(value, function(value, key, object) {
|
baseForIn(value, function(subValue, key, object) {
|
||||||
result = hasOwnProperty.call(object, key);
|
result = hasOwnProperty.call(object, key);
|
||||||
return false;
|
return false;
|
||||||
});
|
});
|
||||||
@@ -3148,7 +3146,7 @@
|
|||||||
// In most environments an object's own properties are iterated before
|
// In most environments an object's own properties are iterated before
|
||||||
// its inherited properties. If the last iterated property is an object's
|
// its inherited properties. If the last iterated property is an object's
|
||||||
// own property then there are no inherited enumerable properties.
|
// own property then there are no inherited enumerable properties.
|
||||||
baseForIn(value, function(value, key) {
|
baseForIn(value, function(subValue, key) {
|
||||||
result = key;
|
result = key;
|
||||||
});
|
});
|
||||||
return typeof result == 'undefined' || hasOwnProperty.call(value, result);
|
return typeof result == 'undefined' || hasOwnProperty.call(value, result);
|
||||||
@@ -4867,7 +4865,7 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Checks if `value` is present in `collection` using `SameValueZero` for
|
* Checks if `value` is present in `collection` using `SameValueZero` for
|
||||||
* equality comparisons. If `fromIndex` is negative, it is used as the offset
|
* equality comparisons. If `fromIndex` is negative, it is used as the offset
|
||||||
* from the end of the collection.
|
* from the end of the collection.
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -1708,7 +1708,7 @@
|
|||||||
argsList.push(slice.call(arguments));
|
argsList.push(slice.call(arguments));
|
||||||
});
|
});
|
||||||
|
|
||||||
deepEqual(argsList, isDeep ? [[klass], [1, 'a']] : [[klass]]);
|
deepEqual(argsList, isDeep ? [[klass], [1, 'a', klass]] : [[klass]]);
|
||||||
});
|
});
|
||||||
|
|
||||||
test('`_.' + methodName + '` should support the `thisArg` argument', 1, function() {
|
test('`_.' + methodName + '` should support the `thisArg` argument', 1, function() {
|
||||||
|
|||||||
Reference in New Issue
Block a user