Lodash – partial method

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

Syntax Of Lodash partial method

_.partial(func, [partials])

Creates a function that invokes func with partials prepended to the arguments it receives. This Lodash partial method is like _.bind except it does not alter this binding.

Arguments

  • func (Function) − The function to partially apply arguments to.
  • [partials] (…*) − The arguments to be partially applied.

Output

  • (Function) − Returns the new partially applied function.

Example

var _ = require('lodash');
var divide = function(a, b) { return b / a};
var divideBy5 = _.partial(divide, 5);
var result = divideBy5(10);

console.log(result);

var divisionOf10 = _.partial(divide, _, 10)
result = divisionOf10(5)

console.log(result);

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

Command

\>node tester.js

Output

2
2

Next Topic – Click Here

Leave a Reply

WC Captcha − 1 = 3