Lodash method
语法
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
输出