Lodash - overArgs 方法
语法
_.overArgs(func, [transforms=[_.identity]])
创建一个调用 func 的函数其参数会进行变换。
参数
func (函数) - 要包装的函数。
[transforms=[_.identity]] (...(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));
将以上程序保存在**test.js**中。运行以下命令来执行此程序。
命令
\>node tester.js
输出
[ 81, 6 ] [ 100, 10 ]
lodash_function.htm
广告