mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-12 11:57:49 +00:00
Rename bindCallback to toFunction.
This commit is contained in:
committed by
John-David Dalton
parent
454aca7003
commit
c51466935c
@@ -2985,18 +2985,6 @@
|
|||||||
return nativeMin(high, MAX_ARRAY_INDEX);
|
return nativeMin(high, MAX_ARRAY_INDEX);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* A specialized version of `baseIteratee` which only supports `this` binding
|
|
||||||
* and specifying the number of arguments to provide to `func`.
|
|
||||||
*
|
|
||||||
* @private
|
|
||||||
* @param {Function} func The function to bind.
|
|
||||||
* @returns {Function} Returns the callback.
|
|
||||||
*/
|
|
||||||
function bindCallback(func) {
|
|
||||||
return typeof func == 'function' ? func : identity;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a clone of the given array buffer.
|
* Creates a clone of the given array buffer.
|
||||||
*
|
*
|
||||||
@@ -3448,7 +3436,7 @@
|
|||||||
return function(collection, iteratee) {
|
return function(collection, iteratee) {
|
||||||
return (typeof iteratee == 'function' && isArray(collection))
|
return (typeof iteratee == 'function' && isArray(collection))
|
||||||
? arrayFunc(collection, iteratee)
|
? arrayFunc(collection, iteratee)
|
||||||
: eachFunc(collection, bindCallback(iteratee));
|
: eachFunc(collection, toFunction(iteratee));
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -3461,10 +3449,7 @@
|
|||||||
*/
|
*/
|
||||||
function createForIn(objectFunc) {
|
function createForIn(objectFunc) {
|
||||||
return function(object, iteratee) {
|
return function(object, iteratee) {
|
||||||
if (typeof iteratee != 'function') {
|
return objectFunc(object, toFunction(iteratee), keysIn);
|
||||||
iteratee = bindCallback(iteratee);
|
|
||||||
}
|
|
||||||
return objectFunc(object, iteratee, keysIn);
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -3477,10 +3462,7 @@
|
|||||||
*/
|
*/
|
||||||
function createForOwn(objectFunc) {
|
function createForOwn(objectFunc) {
|
||||||
return function(object, iteratee) {
|
return function(object, iteratee) {
|
||||||
if (typeof iteratee != 'function') {
|
return objectFunc(object, toFunction(iteratee));
|
||||||
iteratee = bindCallback(iteratee);
|
|
||||||
}
|
|
||||||
return objectFunc(object, iteratee);
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -4496,6 +4478,17 @@
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Converts `value` to a function if it's not one.
|
||||||
|
*
|
||||||
|
* @private
|
||||||
|
* @param {*} value The value to process.
|
||||||
|
* @returns {Function} Returns the function.
|
||||||
|
*/
|
||||||
|
function toFunction(func) {
|
||||||
|
return typeof func == 'function' ? func : identity;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Converts `value` to an array-like object if it's not one.
|
* Converts `value` to an array-like object if it's not one.
|
||||||
*
|
*
|
||||||
@@ -5694,7 +5687,7 @@
|
|||||||
if (iteratee == null) {
|
if (iteratee == null) {
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
iteratee = bindCallback(iteratee);
|
iteratee = toFunction(iteratee);
|
||||||
return arrayMap(result, function(group) {
|
return arrayMap(result, function(group) {
|
||||||
return arrayReduce(group, iteratee, undefined, true);
|
return arrayReduce(group, iteratee, undefined, true);
|
||||||
});
|
});
|
||||||
@@ -11247,7 +11240,7 @@
|
|||||||
var index = -1,
|
var index = -1,
|
||||||
result = Array(nativeMin(n, MAX_ARRAY_LENGTH));
|
result = Array(nativeMin(n, MAX_ARRAY_LENGTH));
|
||||||
|
|
||||||
iteratee = bindCallback(iteratee);
|
iteratee = toFunction(iteratee);
|
||||||
while (++index < n) {
|
while (++index < n) {
|
||||||
if (index < MAX_ARRAY_LENGTH) {
|
if (index < MAX_ARRAY_LENGTH) {
|
||||||
result[index] = iteratee(index);
|
result[index] = iteratee(index);
|
||||||
|
|||||||
Reference in New Issue
Block a user