mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-09 18:37:50 +00:00
Add overArg helper.
This commit is contained in:
35
lodash.js
35
lodash.js
@@ -1083,6 +1083,20 @@
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a function that invokes `func` with its first argument transformed.
|
||||||
|
*
|
||||||
|
* @private
|
||||||
|
* @param {Function} func The function to wrap.
|
||||||
|
* @param {Function} transform The argument transform.
|
||||||
|
* @returns {Function} Returns the new function.
|
||||||
|
*/
|
||||||
|
function overArg(func, transform) {
|
||||||
|
return function(arg) {
|
||||||
|
return func(transform(arg));
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Replaces all `placeholder` elements in `array` with an internal placeholder
|
* Replaces all `placeholder` elements in `array` with an internal placeholder
|
||||||
* and returns an array of their indexes.
|
* and returns an array of their indexes.
|
||||||
@@ -1278,7 +1292,6 @@
|
|||||||
Symbol = context.Symbol,
|
Symbol = context.Symbol,
|
||||||
Uint8Array = context.Uint8Array,
|
Uint8Array = context.Uint8Array,
|
||||||
enumerate = Reflect ? Reflect.enumerate : undefined,
|
enumerate = Reflect ? Reflect.enumerate : undefined,
|
||||||
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,
|
||||||
propertyIsEnumerable = objectProto.propertyIsEnumerable,
|
propertyIsEnumerable = objectProto.propertyIsEnumerable,
|
||||||
@@ -1291,6 +1304,7 @@
|
|||||||
var nativeCeil = Math.ceil,
|
var nativeCeil = Math.ceil,
|
||||||
nativeFloor = Math.floor,
|
nativeFloor = Math.floor,
|
||||||
nativeGetPrototype = Object.getPrototypeOf,
|
nativeGetPrototype = Object.getPrototypeOf,
|
||||||
|
nativeGetSymbols = Object.getOwnPropertySymbols,
|
||||||
nativeIsFinite = context.isFinite,
|
nativeIsFinite = context.isFinite,
|
||||||
nativeJoin = arrayProto.join,
|
nativeJoin = arrayProto.join,
|
||||||
nativeKeys = Object.keys,
|
nativeKeys = Object.keys,
|
||||||
@@ -3066,9 +3080,7 @@
|
|||||||
* @param {Object} object The object to query.
|
* @param {Object} object The object to query.
|
||||||
* @returns {Array} Returns the array of property names.
|
* @returns {Array} Returns the array of property names.
|
||||||
*/
|
*/
|
||||||
function baseKeys(object) {
|
var baseKeys = overArg(nativeKeys, Object);
|
||||||
return nativeKeys(Object(object));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The base implementation of `_.keysIn` which doesn't skip the constructor
|
* The base implementation of `_.keysIn` which doesn't skip the constructor
|
||||||
@@ -5450,9 +5462,7 @@
|
|||||||
* @param {*} value The value to query.
|
* @param {*} value The value to query.
|
||||||
* @returns {null|Object} Returns the `[[Prototype]]`.
|
* @returns {null|Object} Returns the `[[Prototype]]`.
|
||||||
*/
|
*/
|
||||||
function getPrototype(value) {
|
var getPrototype = overArg(nativeGetPrototype, Object);
|
||||||
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`.
|
||||||
@@ -5461,11 +5471,7 @@
|
|||||||
* @param {Object} object The object to query.
|
* @param {Object} object The object to query.
|
||||||
* @returns {Array} Returns the array of symbols.
|
* @returns {Array} Returns the array of symbols.
|
||||||
*/
|
*/
|
||||||
var getSymbols = !getOwnPropertySymbols ? stubArray : function(object) {
|
var getSymbols = nativeGetSymbols ? overArg(nativeGetSymbols, Object) : stubArray;
|
||||||
// Coerce `object` to an object to avoid non-object errors in V8.
|
|
||||||
// See https://bugs.chromium.org/p/v8/issues/detail?id=3443 for more details.
|
|
||||||
return getOwnPropertySymbols(Object(object));
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates an array of the own and inherited enumerable symbol properties
|
* Creates an array of the own and inherited enumerable symbol properties
|
||||||
@@ -5475,7 +5481,7 @@
|
|||||||
* @param {Object} object The object to query.
|
* @param {Object} object The object to query.
|
||||||
* @returns {Array} Returns the array of symbols.
|
* @returns {Array} Returns the array of symbols.
|
||||||
*/
|
*/
|
||||||
var getSymbolsIn = !getOwnPropertySymbols ? getSymbols : function(object) {
|
var getSymbolsIn = !nativeGetSymbols ? getSymbols : function(object) {
|
||||||
var result = [];
|
var result = [];
|
||||||
while (object) {
|
while (object) {
|
||||||
arrayPush(result, getSymbols(object));
|
arrayPush(result, getSymbols(object));
|
||||||
@@ -9919,8 +9925,7 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a function that invokes `func` with arguments transformed by
|
* Creates a function that invokes `func` with its arguments transformed.
|
||||||
* corresponding `transforms`.
|
|
||||||
*
|
*
|
||||||
* @static
|
* @static
|
||||||
* @since 4.0.0
|
* @since 4.0.0
|
||||||
|
|||||||
Reference in New Issue
Block a user