From 474ae1e91c207c63188cbefa61ce08991c45599a Mon Sep 17 00:00:00 2001 From: jdalton Date: Wed, 18 Feb 2015 23:35:43 -0800 Subject: [PATCH] Allow `isDeep` of `_.clone` to work with more truthy values. --- lodash.src.js | 11 ++++++----- test/test.js | 13 ++++++++----- 2 files changed, 14 insertions(+), 10 deletions(-) diff --git a/lodash.src.js b/lodash.src.js index 6bc73ed09..18eac6170 100644 --- a/lodash.src.js +++ b/lodash.src.js @@ -5394,8 +5394,7 @@ if (!length) { return []; } - // Juggle arguments. - if (typeof isSorted != 'boolean' && isSorted != null) { + if (isSorted != null && typeof isSorted != 'boolean') { thisArg = iteratee; iteratee = isIterateeCall(array, isSorted, thisArg) ? null : isSorted; isSorted = false; @@ -8075,10 +8074,12 @@ * // => 0 */ function clone(value, isDeep, customizer, thisArg) { - // Juggle arguments. - if (typeof isDeep != 'boolean' && isDeep != null) { + if (isDeep && typeof isDeep != 'boolean' && isIterateeCall(value, isDeep, customizer)) { + isDeep = false; + } + else if (typeof isDeep == 'function') { thisArg = customizer; - customizer = isIterateeCall(value, isDeep, thisArg) ? null : isDeep; + customizer = isDeep; isDeep = false; } customizer = typeof customizer == 'function' && bindCallback(customizer, thisArg, 1); diff --git a/test/test.js b/test/test.js index a4ad61db4..5f41925b5 100644 --- a/test/test.js +++ b/test/test.js @@ -1851,12 +1851,15 @@ ok(actual !== expected && actual[0] === expected[0]); }); - test('`_.clone` should work with `isDeep`', 2, function() { - var expected = [{ 'a': 0 }, { 'b': 1 }], - actual = _.clone(expected, true); + test('`_.clone` should work with `isDeep`', 8, function() { + var array = [{ 'a': 0 }, { 'b': 1 }], + values = [true, 1, {}, '1']; - deepEqual(actual, expected); - ok(actual !== expected && actual[0] !== expected[0]); + _.each(values, function(isDeep) { + 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() {