Lodash – overArgs method

  • Post author:
  • Post category:Lodash
  • Post comments:0 Comments
Lodash - overArgs method

Syntax Of Lodash overArgs method

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

Lodash overArgs method 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 ]

Next Topic – Click Here

Leave a Reply

WC Captcha 44 + = 51