mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-01 15:57:48 +00:00
Ensure _.clone and _.cloneDeep work on prototype objects.
This commit is contained in:
@@ -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);
|
||||
}
|
||||
|
||||
11
test/test.js
11
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;
|
||||
|
||||
Reference in New Issue
Block a user