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