Lodash - reArg 方法
语法
_.rearg(func, indexes)
创建一个函数,该函数调用 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' ]