mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-06 17:47:49 +00:00
Optimize _.invoke for arrays.
This commit is contained in:
17
dist/lodash.underscore.js
vendored
17
dist/lodash.underscore.js
vendored
@@ -2481,15 +2481,22 @@
|
||||
* // => [['1', '2', '3'], ['4', '5', '6']]
|
||||
*/
|
||||
function invoke(collection, methodName) {
|
||||
var args = slice(arguments, 2),
|
||||
index = -1,
|
||||
var index = -1,
|
||||
isFunc = typeof methodName == 'function',
|
||||
length = collection ? collection.length : 0,
|
||||
result = Array(typeof length == 'number' ? length : 0);
|
||||
|
||||
baseEach(collection, function(value) {
|
||||
result[++index] = (isFunc ? methodName : value[methodName]).apply(value, args);
|
||||
});
|
||||
if (arguments.length < 3 && typeof length == 'number') {
|
||||
while (++index < length) {
|
||||
var value = collection[index];
|
||||
result[index] = isFunc ? methodName.call(value) : value[methodName]();
|
||||
}
|
||||
} else {
|
||||
var args = slice(arguments, 2);
|
||||
baseEach(collection, function(value) {
|
||||
result[++index] = (isFunc ? methodName : value[methodName]).apply(value, args);
|
||||
});
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user