mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-10 10:57:49 +00:00
Use getPrototypeOf to set inheritance when constructor is a function. [closes #2018]
This commit is contained in:
17
lodash.js
17
lodash.js
@@ -5055,11 +5055,9 @@
|
|||||||
* @returns {Object} Returns the initialized clone.
|
* @returns {Object} Returns the initialized clone.
|
||||||
*/
|
*/
|
||||||
function initCloneObject(object) {
|
function initCloneObject(object) {
|
||||||
if (isPrototype(object)) {
|
return (isFunction(object.constructor) && !isPrototype(object))
|
||||||
return {};
|
? baseCreate(getPrototypeOf(object))
|
||||||
}
|
: {};
|
||||||
var Ctor = object.constructor;
|
|
||||||
return baseCreate(isFunction(Ctor) ? Ctor.prototype : undefined);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -5206,7 +5204,7 @@
|
|||||||
*/
|
*/
|
||||||
function isPrototype(value) {
|
function isPrototype(value) {
|
||||||
var Ctor = value && value.constructor,
|
var Ctor = value && value.constructor,
|
||||||
proto = (typeof Ctor == 'function' && Ctor.prototype) || objectProto;
|
proto = (isFunction(Ctor) && Ctor.prototype) || objectProto;
|
||||||
|
|
||||||
return value === proto;
|
return value === proto;
|
||||||
}
|
}
|
||||||
@@ -10288,10 +10286,7 @@
|
|||||||
objectToString.call(value) != objectTag || isHostObject(value)) {
|
objectToString.call(value) != objectTag || isHostObject(value)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
var proto = objectProto;
|
var proto = getPrototypeOf(value);
|
||||||
if (typeof value.constructor == 'function') {
|
|
||||||
proto = getPrototypeOf(value);
|
|
||||||
}
|
|
||||||
if (proto === null) {
|
if (proto === null) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -11919,7 +11914,7 @@
|
|||||||
if (isArr) {
|
if (isArr) {
|
||||||
accumulator = isArray(object) ? new Ctor : [];
|
accumulator = isArray(object) ? new Ctor : [];
|
||||||
} else {
|
} else {
|
||||||
accumulator = baseCreate(isFunction(Ctor) ? Ctor.prototype : undefined);
|
accumulator = isFunction(Ctor) ? baseCreate(getPrototypeOf(object)) : {};
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
accumulator = {};
|
accumulator = {};
|
||||||
|
|||||||
Reference in New Issue
Block a user