diff --git a/lodash.js b/lodash.js index d432343be..82e16b789 100644 --- a/lodash.js +++ b/lodash.js @@ -4956,6 +4956,9 @@ * @returns {Object} Returns the initialized clone. */ function initCloneObject(object) { + if (isPrototype(object)) { + return {}; + } var Ctor = object.constructor; return baseCreate(isFunction(Ctor) ? Ctor.prototype : undefined); } diff --git a/test/test.js b/test/test.js index 8288b3a53..78dcdaa22 100644 --- a/test/test.js +++ b/test/test.js @@ -2520,13 +2520,22 @@ assert.strictEqual(actual.lastIndex, 3); }); + QUnit.test('`_.' + methodName + '` should clone prototype objects', function(assert) { + assert.expect(2); + + var actual = func(Foo.prototype); + + assert.notOk(actual instanceof Foo); + assert.deepEqual(actual, { 'b': 1 }); + }); + QUnit.test('`_.' + methodName + '` should create clone with the same `[[Prototype]]` as `value`', function(assert) { assert.expect(1); assert.ok(func(new Foo) instanceof Foo); }); - QUnit.test('should ensure `value` constructor is a function before using its `[[Prototype]]`', function(assert) { + QUnit.test('`_.' + methodName + '` should ensure `value` constructor is a function before using its `[[Prototype]]`', function(assert) { assert.expect(1); Foo.prototype.constructor = null;