Lodash - overArgs 方法
语法
_.overArgs(func, [transforms=[_.identity]])
创建一个函数,该函数调用 func 并转换其参数。
参数
func (Function) − 要包装的函数。
[transforms=[_.identity]] (...(Function|Function[])) − 参数转换。
输出
(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));
将上述程序保存在tester.js中。运行以下命令执行该程序。
命令
\>node tester.js
输出
[ 81, 6 ] [ 100, 10 ]