diff --git a/lodash.js b/lodash.js index db3d289d5..4cb33c35f 100644 --- a/lodash.js +++ b/lodash.js @@ -1486,11 +1486,10 @@ * @private * @param {*} value The value to wrap. * @param {boolean} [chainAll] Enable chaining for all wrapper methods. - * @param {Array} [actions=[]] Actions to peform to resolve the unwrapped value. */ - function LodashWrapper(value, chainAll, actions) { + function LodashWrapper(value, chainAll) { this.__wrapped__ = value; - this.__actions__ = actions || []; + this.__actions__ = []; this.__chain__ = !!chainAll; this.__index__ = 0; this.__values__ = undefined; @@ -4347,9 +4346,14 @@ * @returns {Object} Returns the cloned wrapper. */ function wrapperClone(wrapper) { - return wrapper instanceof LazyWrapper - ? wrapper.clone() - : new LodashWrapper(wrapper.__wrapped__, wrapper.__chain__, copyArray(wrapper.__actions__)); + if (wrapper instanceof LazyWrapper) { + return wrapper.clone(); + } + var result = new LodashWrapper(wrapper.__wrapped__, wrapper.__chain__); + result.__actions__ = wrapper.__actions__; + result.__index__ = wrapper.__index__; + result.__values__ = wrapper.__values__; + return result; } /*------------------------------------------------------------------------*/ @@ -5950,6 +5954,8 @@ while (parent instanceof baseLodash) { var clone = wrapperClone(parent); + clone.__index__ = 0; + clone.__values__ = undefined; if (result) { previous.__wrapped__ = clone; } else { diff --git a/test/test.js b/test/test.js index 93d8e44e1..302cf09bc 100644 --- a/test/test.js +++ b/test/test.js @@ -16637,6 +16637,22 @@ skipTest(2); } }); + + test('should reset iterator data on cloned sequences', 2, function() { + if (!isNpm) { + var array1 = [2, 4], + array2 = [6, 8], + wrapped1 = _(array1).map(square); + + deepEqual(_.toArray(wrapped1), [4, 16]); + + var wrapped2 = wrapped1.plant(array2); + deepEqual(_.toArray(wrapped2), [36, 64]); + } + else { + skipTest(2); + } + }); }()); /*--------------------------------------------------------------------------*/