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
廣告