Skip to content

methodOf

js
_.methodOf(object, [args])

选项对象。此方法创建一个函数,该函数在 object 的给定路径处调用该方法。将向调用的方法提供任何其他参数。

¥The opposite of _.method; this method creates a function that invokes the method at a given path of object. Any additional arguments are provided to the invoked method.

新增于

¥Since

3.7.0

参数

¥Arguments

  1. object (对象):的反面;

    ¥object (Object): The object to query.

  2. [args] (...*):用于调用方法的参数。

    ¥[args] (...)*: The arguments to invoke the method with.

返回

¥Returns

(函数):返回新的调用函数。

¥(Function): Returns the new invoker function.

示例

¥Example

js
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]

Lodash v4.17 中文网 - 粤ICP备13048890号