mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-09 10:27:49 +00:00
Bump to v3.6.0.
This commit is contained in:
@@ -1,4 +1,7 @@
|
||||
define(['../internal/baseInvoke', '../internal/baseSlice'], function(baseInvoke, baseSlice) {
|
||||
define(['../internal/baseEach', '../internal/isLength', '../function/restParam'], function(baseEach, isLength, restParam) {
|
||||
|
||||
/** Used as a safe reference for `undefined` in pre-ES5 environments. */
|
||||
var undefined;
|
||||
|
||||
/**
|
||||
* Invokes the method named by `methodName` on each element in `collection`,
|
||||
@@ -22,9 +25,18 @@ define(['../internal/baseInvoke', '../internal/baseSlice'], function(baseInvoke,
|
||||
* _.invoke([123, 456], String.prototype.split, '');
|
||||
* // => [['1', '2', '3'], ['4', '5', '6']]
|
||||
*/
|
||||
function invoke(collection, methodName) {
|
||||
return baseInvoke(collection, methodName, baseSlice(arguments, 2));
|
||||
}
|
||||
var invoke = restParam(function(collection, methodName, args) {
|
||||
var index = -1,
|
||||
isFunc = typeof methodName == 'function',
|
||||
length = collection ? collection.length : 0,
|
||||
result = isLength(length) ? Array(length) : [];
|
||||
|
||||
baseEach(collection, function(value) {
|
||||
var func = isFunc ? methodName : (value != null && value[methodName]);
|
||||
result[++index] = func ? func.apply(value, args) : undefined;
|
||||
});
|
||||
return result;
|
||||
});
|
||||
|
||||
return invoke;
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user