Lodash教程

Lodash reArg method

语法

_.rearg(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.

参数

func (Function) − The function to rearrange arguments for. indexes (...(number|number[])) − The arranged argument indexes.

输出

(Function) − Returns the new function.

实例

var _ = require('lodash');
var rearged = _.rearg(function(a, b, c) {
   return [a, b, c];
}, [2, 0, 1]);
 
console.log(rearged('b', 'c', 'a'));
Save the above program in tester.js. Run the following command to execute this program.

Command

\>node tester.js

输出

[ 'a', 'b', 'c' ]
昵称: 邮箱:
Copyright © 2022 立地货 All Rights Reserved.
备案号:京ICP备14037608号-4