主题
rearg
js
_.rearg(func, indexes)
创建一个函数,该函数调用 func
,其参数按照指定的 indexes
排列,其中第一个索引处的参数值作为第一个参数提供,第二个索引处的参数值作为第二个参数提供,依此类推。
¥Creates a function that invokes func
with arguments arranged according to the specified indexes
where the argument value at the first index is provided as the first argument, the argument value at the second index is provided as the second argument, and so on.
新增于
¥Since
3.0.0
参数
¥Arguments
func
(函数):重新排列参数的函数。¥
func
(Function): The function to rearrange arguments for.indexes
(...(数值|数值[])):排列的参数索引。¥
indexes
(...(number|number[])): The arranged argument indexes.
返回
¥Returns
(函数):返回新函数。
¥(Function): Returns the new function.
示例
¥Example
js
var rearged = _.rearg(function(a, b, c) {
return [a, b, c];
}, [2, 0, 1]);
rearged('b', 'c', 'a')
// => ['a', 'b', 'c']