Lodash - overArgs method



Syntax

_.overArgs(func, [transforms=[_.identity]])

Creates a function that invokes func with its arguments transformed.

Arguments

  • func (Function) − The function to wrap.

  • [transforms=[_.identity]] (...(Function|Function[])) − The argument transforms.

Output

  • (Function) − Returns the new function.

Example

var _ = require('lodash');

function doubled(n) {
   return n * 2;
}
function square(n) {
   return n * n;
}
var func = _.overArgs(function(x, y) {
   return [x, y];
}, [square, doubled]);
 
console.log(func(9, 3));
console.log(func(10, 5));

Save the above program in tester.js. Run the following command to execute this program.

Command

\>node tester.js

Output

[ 81, 6 ]
[ 100, 10 ]
lodash_function.htm
Advertisements