mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-01 23:57:49 +00:00
Add getPlaceholder helper.
This commit is contained in:
47
lodash.js
47
lodash.js
@@ -4234,10 +4234,9 @@
|
||||
|
||||
function wrapper() {
|
||||
var length = arguments.length,
|
||||
index = length,
|
||||
args = Array(length),
|
||||
fn = (this && this !== root && this instanceof wrapper) ? Ctor : func,
|
||||
placeholder = lodash.placeholder || wrapper.placeholder;
|
||||
index = length,
|
||||
placeholder = getPlaceholder(wrapper);
|
||||
|
||||
while (index--) {
|
||||
args[index] = arguments[index];
|
||||
@@ -4247,9 +4246,11 @@
|
||||
: replaceHolders(args, placeholder);
|
||||
|
||||
length -= holders.length;
|
||||
return length < arity
|
||||
? createRecurryWrapper(func, bitmask, createHybridWrapper, placeholder, undefined, args, holders, undefined, undefined, arity - length)
|
||||
: apply(fn, this, args);
|
||||
if (length < arity) {
|
||||
return createRecurryWrapper(func, bitmask, createHybridWrapper, placeholder, undefined, args, holders, undefined, undefined, arity - length);
|
||||
}
|
||||
var fn = (this && this !== root && this instanceof wrapper) ? Ctor : func;
|
||||
return apply(fn, this, args);
|
||||
}
|
||||
return wrapper;
|
||||
}
|
||||
@@ -4350,7 +4351,7 @@
|
||||
args[index] = arguments[index];
|
||||
}
|
||||
if (isCurried) {
|
||||
var placeholder = lodash.placeholder || wrapper.placeholder,
|
||||
var placeholder = getPlaceholder(wrapper),
|
||||
holdersCount = countHolders(args, placeholder);
|
||||
}
|
||||
if (partials) {
|
||||
@@ -4959,6 +4960,18 @@
|
||||
return isNative(value) ? value : undefined;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the argument placeholder value for `func`.
|
||||
*
|
||||
* @private
|
||||
* @param {Function} func The function to inspect.
|
||||
* @returns {*} Returns the placeholder value.
|
||||
*/
|
||||
function getPlaceholder(func) {
|
||||
var object = hasOwnProperty.call(lodash, 'placeholder') ? lodash : func;
|
||||
return object.placeholder;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates an array of the own symbol properties of `object`.
|
||||
*
|
||||
@@ -8490,9 +8503,7 @@
|
||||
var bind = rest(function(func, thisArg, partials) {
|
||||
var bitmask = BIND_FLAG;
|
||||
if (partials.length) {
|
||||
var placeholder = lodash.placeholder || bind.placeholder,
|
||||
holders = replaceHolders(partials, placeholder);
|
||||
|
||||
var holders = replaceHolders(partials, getPlaceholder(bind));
|
||||
bitmask |= PARTIAL_FLAG;
|
||||
}
|
||||
return createWrapper(func, bitmask, thisArg, partials, holders);
|
||||
@@ -8545,9 +8556,7 @@
|
||||
var bindKey = rest(function(object, key, partials) {
|
||||
var bitmask = BIND_FLAG | BIND_KEY_FLAG;
|
||||
if (partials.length) {
|
||||
var placeholder = lodash.placeholder || bindKey.placeholder,
|
||||
holders = replaceHolders(partials, placeholder);
|
||||
|
||||
var holders = replaceHolders(partials, getPlaceholder(bindKey));
|
||||
bitmask |= PARTIAL_FLAG;
|
||||
}
|
||||
return createWrapper(key, bitmask, object, partials, holders);
|
||||
@@ -8596,7 +8605,7 @@
|
||||
function curry(func, arity, guard) {
|
||||
arity = guard ? undefined : arity;
|
||||
var result = createWrapper(func, CURRY_FLAG, undefined, undefined, undefined, undefined, undefined, arity);
|
||||
result.placeholder = lodash.placeholder || curry.placeholder;
|
||||
result.placeholder = getPlaceholder(curry);
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -8640,7 +8649,7 @@
|
||||
function curryRight(func, arity, guard) {
|
||||
arity = guard ? undefined : arity;
|
||||
var result = createWrapper(func, CURRY_RIGHT_FLAG, undefined, undefined, undefined, undefined, undefined, arity);
|
||||
result.placeholder = lodash.placeholder || curryRight.placeholder;
|
||||
result.placeholder = getPlaceholder(curryRight);
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -9064,9 +9073,7 @@
|
||||
* // => 'hi fred'
|
||||
*/
|
||||
var partial = rest(function(func, partials) {
|
||||
var placeholder = lodash.placeholder || partial.placeholder,
|
||||
holders = replaceHolders(partials, placeholder);
|
||||
|
||||
var holders = replaceHolders(partials, getPlaceholder(partial));
|
||||
return createWrapper(func, PARTIAL_FLAG, undefined, partials, holders);
|
||||
});
|
||||
|
||||
@@ -9102,9 +9109,7 @@
|
||||
* // => 'hello fred'
|
||||
*/
|
||||
var partialRight = rest(function(func, partials) {
|
||||
var placeholder = lodash.placeholder || partialRight.placeholder,
|
||||
holders = replaceHolders(partials, placeholder);
|
||||
|
||||
var holders = replaceHolders(partials, getPlaceholder(partialRight));
|
||||
return createWrapper(func, PARTIAL_RIGHT_FLAG, undefined, partials, holders);
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user