From a7bb6b53833914f79fac1cf9d7fef675425d4f1f Mon Sep 17 00:00:00 2001 From: John-David Dalton Date: Fri, 4 Mar 2016 09:17:00 -0800 Subject: [PATCH] Add `getPrototype` helper. --- lodash.js | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/lodash.js b/lodash.js index 10cee4c3f..331e2ac00 100644 --- a/lodash.js +++ b/lodash.js @@ -1364,7 +1364,6 @@ Uint8Array = context.Uint8Array, clearTimeout = context.clearTimeout, enumerate = Reflect ? Reflect.enumerate : undefined, - getPrototypeOf = Object.getPrototypeOf, getOwnPropertySymbols = Object.getOwnPropertySymbols, iteratorSymbol = typeof (iteratorSymbol = Symbol && Symbol.iterator) == 'symbol' ? iteratorSymbol : undefined, objectCreate = Object.create, @@ -1375,6 +1374,7 @@ /* Built-in method references for those with the same name as other `lodash` methods. */ var nativeCeil = Math.ceil, nativeFloor = Math.floor, + nativeGetPrototype = Object.getPrototypeOf, nativeIsFinite = context.isFinite, nativeJoin = arrayProto.join, nativeKeys = Object.keys, @@ -2774,7 +2774,7 @@ // that are composed entirely of index properties, return `false` for // `hasOwnProperty` checks of them. 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; } + /** + * 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`. * @@ -5100,7 +5111,7 @@ var result = []; while (object) { arrayPush(result, getSymbols(object)); - object = getPrototypeOf(object); + object = getPrototype(object); } return result; }; @@ -5227,7 +5238,7 @@ */ function initCloneObject(object) { return (typeof object.constructor == 'function' && !isPrototype(object)) - ? baseCreate(getPrototypeOf(object)) + ? baseCreate(getPrototype(object)) : {}; } @@ -10636,7 +10647,7 @@ objectToString.call(value) != objectTag || isHostObject(value)) { return false; } - var proto = getPrototypeOf(value); + var proto = getPrototype(value); if (proto === null) { return true; } @@ -12344,7 +12355,7 @@ if (isArr) { accumulator = isArray(object) ? new Ctor : []; } else { - accumulator = isFunction(Ctor) ? baseCreate(getPrototypeOf(object)) : {}; + accumulator = isFunction(Ctor) ? baseCreate(getPrototype(object)) : {}; } } else { accumulator = {};