mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-01-31 07:17:50 +00:00
31 lines
1.1 KiB
JavaScript
31 lines
1.1 KiB
JavaScript
define(['../internal/baseInvoke', '../internal/baseSlice'], function(baseInvoke, baseSlice) {
|
|
|
|
/**
|
|
* Invokes the method named by `methodName` on each element in `collection`,
|
|
* returning an array of the results of each invoked method. Any additional
|
|
* arguments are provided to each invoked method. If `methodName` is a function
|
|
* it is invoked for, and `this` bound to, each element in `collection`.
|
|
*
|
|
* @static
|
|
* @memberOf _
|
|
* @category Collection
|
|
* @param {Array|Object|string} collection The collection to iterate over.
|
|
* @param {Function|string} methodName The name of the method to invoke or
|
|
* the function invoked per iteration.
|
|
* @param {...*} [args] The arguments to invoke the method with.
|
|
* @returns {Array} Returns the array of results.
|
|
* @example
|
|
*
|
|
* _.invoke([[5, 1, 7], [3, 2, 1]], 'sort');
|
|
* // => [[1, 5, 7], [1, 2, 3]]
|
|
*
|
|
* _.invoke([123, 456], String.prototype.split, '');
|
|
* // => [['1', '2', '3'], ['4', '5', '6']]
|
|
*/
|
|
function invoke(collection, methodName) {
|
|
return baseInvoke(collection, methodName, baseSlice(arguments, 2));
|
|
}
|
|
|
|
return invoke;
|
|
});
|