Lodash教程

Lodash method

语法

_.method(path, [args])
Creates a function that invokes the method at path of a given object. Any additional arguments are provided to the invoked method.

参数

path (Array|string) − The path of the method to invoke. [args] (...*) − The arguments to invoke the method with.

输出

(Function) − Returns the new invoker function.

实例

var _ = require('lodash');
var objects = [
   { 'a': { 'b': _.constant(4) } },
   { 'a': { 'b': _.constant(5) } }
];
 
console.log(_.map(objects, _.method('a.b')));
console.log(_.map(objects, _.method(['a', 'b'])));
Save the above program in tester.js. Run the following command to execute this program.

Command

\>node tester.js

输出

[ 4, 5 ]
[ 4, 5 ]
昵称: 邮箱:
Copyright © 2022 立地货 All Rights Reserved.
备案号:京ICP备14037608号-4