mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-06 01:47:48 +00:00
Allow isDeep of _.clone to work with more truthy values.
This commit is contained in:
@@ -5394,8 +5394,7 @@
|
|||||||
if (!length) {
|
if (!length) {
|
||||||
return [];
|
return [];
|
||||||
}
|
}
|
||||||
// Juggle arguments.
|
if (isSorted != null && typeof isSorted != 'boolean') {
|
||||||
if (typeof isSorted != 'boolean' && isSorted != null) {
|
|
||||||
thisArg = iteratee;
|
thisArg = iteratee;
|
||||||
iteratee = isIterateeCall(array, isSorted, thisArg) ? null : isSorted;
|
iteratee = isIterateeCall(array, isSorted, thisArg) ? null : isSorted;
|
||||||
isSorted = false;
|
isSorted = false;
|
||||||
@@ -8075,10 +8074,12 @@
|
|||||||
* // => 0
|
* // => 0
|
||||||
*/
|
*/
|
||||||
function clone(value, isDeep, customizer, thisArg) {
|
function clone(value, isDeep, customizer, thisArg) {
|
||||||
// Juggle arguments.
|
if (isDeep && typeof isDeep != 'boolean' && isIterateeCall(value, isDeep, customizer)) {
|
||||||
if (typeof isDeep != 'boolean' && isDeep != null) {
|
isDeep = false;
|
||||||
|
}
|
||||||
|
else if (typeof isDeep == 'function') {
|
||||||
thisArg = customizer;
|
thisArg = customizer;
|
||||||
customizer = isIterateeCall(value, isDeep, thisArg) ? null : isDeep;
|
customizer = isDeep;
|
||||||
isDeep = false;
|
isDeep = false;
|
||||||
}
|
}
|
||||||
customizer = typeof customizer == 'function' && bindCallback(customizer, thisArg, 1);
|
customizer = typeof customizer == 'function' && bindCallback(customizer, thisArg, 1);
|
||||||
|
|||||||
13
test/test.js
13
test/test.js
@@ -1851,12 +1851,15 @@
|
|||||||
ok(actual !== expected && actual[0] === expected[0]);
|
ok(actual !== expected && actual[0] === expected[0]);
|
||||||
});
|
});
|
||||||
|
|
||||||
test('`_.clone` should work with `isDeep`', 2, function() {
|
test('`_.clone` should work with `isDeep`', 8, function() {
|
||||||
var expected = [{ 'a': 0 }, { 'b': 1 }],
|
var array = [{ 'a': 0 }, { 'b': 1 }],
|
||||||
actual = _.clone(expected, true);
|
values = [true, 1, {}, '1'];
|
||||||
|
|
||||||
deepEqual(actual, expected);
|
_.each(values, function(isDeep) {
|
||||||
ok(actual !== expected && actual[0] !== expected[0]);
|
var actual = _.clone(array, isDeep);
|
||||||
|
deepEqual(actual, array);
|
||||||
|
ok(actual !== array && actual[0] !== array[0]);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
test('`_.cloneDeep` should deep clone objects with circular references', 1, function() {
|
test('`_.cloneDeep` should deep clone objects with circular references', 1, function() {
|
||||||
|
|||||||
Reference in New Issue
Block a user