主题
method
js
_.method(path, [args])
创建一个调用给定对象的 path
处的方法的函数。将向调用的方法提供任何其他参数。
¥Creates a function that invokes the method at path
of a given object. Any additional arguments are provided to the invoked method.
新增于
¥Since
3.7.0
参数
¥Arguments
path
(数组|字符串):要调用的方法的路径。¥
path
(Array|string): The path of the method to invoke.[args]
(...*):用于调用方法的参数。¥
[args]
(...)*: The arguments to invoke the method with.
返回
¥Returns
(函数):返回新的调用函数。
¥(Function): Returns the new invoker function.
示例
¥Example
js
var objects = [
{ 'a': { 'b': _.constant(2) } },
{ 'a': { 'b': _.constant(1) } }
];
_.map(objects, _.method('a.b'));
// => [2, 1]
_.map(objects, _.method(['a', 'b']));
// => [2, 1]