2016-07-24 09:52:04 -07:00
|
|
|
define(['./_baseInvoke', './_baseRest'], function(baseInvoke, baseRest) {
|
2015-12-16 17:49:35 -08:00
|
|
|
|
|
|
|
|
/**
|
2015-12-16 17:53:20 -08:00
|
|
|
* Creates a function that invokes the method at `path` of a given object.
|
2015-12-16 17:51:09 -08:00
|
|
|
* Any additional arguments are provided to the invoked method.
|
2015-12-16 17:49:35 -08:00
|
|
|
*
|
|
|
|
|
* @static
|
|
|
|
|
* @memberOf _
|
2016-03-26 00:00:01 -07:00
|
|
|
* @since 3.7.0
|
2015-12-16 17:53:20 -08:00
|
|
|
* @category Util
|
2015-12-16 17:49:35 -08:00
|
|
|
* @param {Array|string} path The path of the method to invoke.
|
2015-12-16 17:51:09 -08:00
|
|
|
* @param {...*} [args] The arguments to invoke the method with.
|
2016-05-07 11:49:46 -07:00
|
|
|
* @returns {Function} Returns the new invoker function.
|
2015-12-16 17:49:35 -08:00
|
|
|
* @example
|
|
|
|
|
*
|
|
|
|
|
* var objects = [
|
2016-04-07 21:35:23 -07:00
|
|
|
* { 'a': { 'b': _.constant(2) } },
|
|
|
|
|
* { 'a': { 'b': _.constant(1) } }
|
2015-12-16 17:49:35 -08:00
|
|
|
* ];
|
|
|
|
|
*
|
2016-04-07 21:35:23 -07:00
|
|
|
* _.map(objects, _.method('a.b'));
|
2015-12-16 17:49:35 -08:00
|
|
|
* // => [2, 1]
|
|
|
|
|
*
|
2016-04-07 21:35:23 -07:00
|
|
|
* _.map(objects, _.method(['a', 'b']));
|
2016-03-26 00:00:01 -07:00
|
|
|
* // => [2, 1]
|
2015-12-16 17:49:35 -08:00
|
|
|
*/
|
2016-07-24 09:52:04 -07:00
|
|
|
var method = baseRest(function(path, args) {
|
2015-12-16 17:49:35 -08:00
|
|
|
return function(object) {
|
2015-12-16 17:53:20 -08:00
|
|
|
return baseInvoke(object, path, args);
|
2015-12-16 17:50:05 -08:00
|
|
|
};
|
2015-12-16 17:49:35 -08:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
return method;
|
|
|
|
|
});
|