Skip to content

invoke

js
_.invoke(object, path, [args])

调用 objectpath 处的方法。

¥Invokes the method at path of object.

新增于

¥Since

4.0.0

参数

¥Arguments

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

    ¥object (Object): The object to query.

  2. path (数组|字符串):要调用的方法的路径。

    ¥path (Array|string): The path of the method to invoke.

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

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

返回

¥Returns

(*):返回调用方法的结果。

¥()*: Returns the result of the invoked method.

示例

¥Example

js
var object = { 'a': [{ 'b': { 'c': [1, 2, 3, 4] } }] };

_.invoke(object, 'a[0].b.c.slice', 1, 3);
// => [2, 3]

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