Lodash overArgs method
语法
_.overArgs(func, [transforms=[_.identity]])
Creates a function that invokes func with its arguments transformed.
参数
func (Function) − The function to wrap.
[transforms=[_.identity]] (...(Function|Function[])) − The argument transforms.
输出
(Function) − Returns the new function.
实例
var _ = require('lodash');
function doubled(n) {
return n * 2;
}
function square(n) {
return n * n;
}
var func = _.overArgs(function(x, y) {
return [x, y];
}, [square, doubled]);
console.log(func(9, 3));
console.log(func(10, 5));
Save the above program in
tester.js. Run the following command to execute this program.
Command
输出