SIGN IN SIGN UP

A modern JavaScript utility library delivering modularity, performance, & extras.

0 0 21 JavaScript
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:51:09 -08:00
* The opposite of `_.method`; this method creates a function that invokes
2015-12-16 17:53:20 -08:00
* the method at a given path of `object`. Any additional arguments are
2015-12-16 17:51:09 -08:00
* 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 {Object} object The object to query.
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 array = _.times(3, _.constant),
* object = { 'a': array, 'b': array, 'c': array };
*
* _.map(['a[2]', 'c[0]'], _.methodOf(object));
* // => [2, 0]
*
* _.map([['a', '2'], ['c', '0']], _.methodOf(object));
* // => [2, 0]
*/
2016-07-24 09:52:04 -07:00
var methodOf = baseRest(function(object, args) {
2015-12-16 17:49:35 -08:00
return function(path) {
2015-12-16 17:53:20 -08:00
return baseInvoke(object, path, args);
2015-12-16 17:49:35 -08:00
};
});
return methodOf;
});