rearg source npm

_.rearg(func, indexes)

创建一个调用 func 的函数。 所传递的参数根据 indexes 调整到对应位置。 第一个 index 对应到第一个传参,第二个 index 对应到第二个传参,以此类推。

参数

  1. func (Function)

    待调用的函数

  2. indexes (...(number|number[])

    重新排列参数的位置,单独指定或者指定在数组中

返回值 (Function)

返回新的函数

示例

var rearged = _.rearg(function(a, b, c) {
  return [a, b, c];
}, 2, 0, 1);

rearged('b', 'c', 'a')
// => ['a', 'b', 'c']