Add getPrototype helper.

This commit is contained in:
John-David Dalton
2016-03-04 09:17:00 -08:00
parent e02ce1ea8b
commit a7bb6b5383

View File

@@ -1364,7 +1364,6 @@
Uint8Array = context.Uint8Array, Uint8Array = context.Uint8Array,
clearTimeout = context.clearTimeout, clearTimeout = context.clearTimeout,
enumerate = Reflect ? Reflect.enumerate : undefined, enumerate = Reflect ? Reflect.enumerate : undefined,
getPrototypeOf = Object.getPrototypeOf,
getOwnPropertySymbols = Object.getOwnPropertySymbols, getOwnPropertySymbols = Object.getOwnPropertySymbols,
iteratorSymbol = typeof (iteratorSymbol = Symbol && Symbol.iterator) == 'symbol' ? iteratorSymbol : undefined, iteratorSymbol = typeof (iteratorSymbol = Symbol && Symbol.iterator) == 'symbol' ? iteratorSymbol : undefined,
objectCreate = Object.create, objectCreate = Object.create,
@@ -1375,6 +1374,7 @@
/* Built-in method references for those with the same name as other `lodash` methods. */ /* Built-in method references for those with the same name as other `lodash` methods. */
var nativeCeil = Math.ceil, var nativeCeil = Math.ceil,
nativeFloor = Math.floor, nativeFloor = Math.floor,
nativeGetPrototype = Object.getPrototypeOf,
nativeIsFinite = context.isFinite, nativeIsFinite = context.isFinite,
nativeJoin = arrayProto.join, nativeJoin = arrayProto.join,
nativeKeys = Object.keys, nativeKeys = Object.keys,
@@ -2774,7 +2774,7 @@
// that are composed entirely of index properties, return `false` for // that are composed entirely of index properties, return `false` for
// `hasOwnProperty` checks of them. // `hasOwnProperty` checks of them.
return hasOwnProperty.call(object, key) || return hasOwnProperty.call(object, key) ||
(typeof object == 'object' && key in object && getPrototypeOf(object) === null); (typeof object == 'object' && key in object && getPrototype(object) === null);
} }
/** /**
@@ -5068,6 +5068,17 @@
return object.placeholder; return object.placeholder;
} }
/**
* Gets the `[[Prototype]]` of `value`.
*
* @private
* @param {*} value The value to query.
* @returns {null|Object} Returns the `[[Prototype]]`.
*/
function getPrototype(value) {
return nativeGetPrototype(Object(value));
}
/** /**
* Creates an array of the own enumerable symbol properties of `object`. * Creates an array of the own enumerable symbol properties of `object`.
* *
@@ -5100,7 +5111,7 @@
var result = []; var result = [];
while (object) { while (object) {
arrayPush(result, getSymbols(object)); arrayPush(result, getSymbols(object));
object = getPrototypeOf(object); object = getPrototype(object);
} }
return result; return result;
}; };
@@ -5227,7 +5238,7 @@
*/ */
function initCloneObject(object) { function initCloneObject(object) {
return (typeof object.constructor == 'function' && !isPrototype(object)) return (typeof object.constructor == 'function' && !isPrototype(object))
? baseCreate(getPrototypeOf(object)) ? baseCreate(getPrototype(object))
: {}; : {};
} }
@@ -10636,7 +10647,7 @@
objectToString.call(value) != objectTag || isHostObject(value)) { objectToString.call(value) != objectTag || isHostObject(value)) {
return false; return false;
} }
var proto = getPrototypeOf(value); var proto = getPrototype(value);
if (proto === null) { if (proto === null) {
return true; return true;
} }
@@ -12344,7 +12355,7 @@
if (isArr) { if (isArr) {
accumulator = isArray(object) ? new Ctor : []; accumulator = isArray(object) ? new Ctor : [];
} else { } else {
accumulator = isFunction(Ctor) ? baseCreate(getPrototypeOf(object)) : {}; accumulator = isFunction(Ctor) ? baseCreate(getPrototype(object)) : {};
} }
} else { } else {
accumulator = {}; accumulator = {};