Lodash - reArg 方法
語法
_.rearg(func, indexes)
建立一個函式,使用指定索引排列的 arguments 呼叫 func,其中第一個索引處的引數值作為第一個引數提供,第二個索引處的引數值作為第二個引數提供,依此類推。
引數
func (Function) − 要重新排列引數的函式。
indexes (...(number|number[])) − 已排列的引數索引。
輸出
(Function) − 返回新函式。
示例
var _ = require('lodash');
var rearged = _.rearg(function(a, b, c) {
return [a, b, c];
}, [2, 0, 1]);
console.log(rearged('b', 'c', 'a'));
將以上程式儲存在 tester.js 中。執行以下命令來執行此程式。
命令
\>node tester.js
輸出
[ 'a', 'b', 'c' ]
lodash_function.htm
廣告