Lodash教程

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

\>node tester.js

输出

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