Open In App

Underscore.js _.flip2() Method

Last Updated : 17 Aug, 2020
Improve
Improve
Like Article
Like
Save
Share
Report

The _.flip2() method returns a function that works identically to given function but accepts the first two arguments in reverse order. The order of all rest arguments remains the same.

Syntax:

_.flip2( function );

Parameters: This method takes a function that takes some arguments.

Return Value: This method returns a function.

Note: This will not work in normal JavaScript because it requires the underscore.js contrib library to be installed. 

underscore.js contrib library can be installed using npm install underscore-contrib –save.

Example 1:

Javascript




// Defining underscore contrib variable
var _ = require('underscore-contrib'); 
  
function gfgFunc(a, b, c) {
    return "Value of a is " +
    a + " and Value of b is "
    b + " and Value of c is " + c;
}
  
var abc = _.flip2(gfgFunc);
  
console.log(abc(1, 2, 3));


Output:

Value of a is 2 and Value of b is 1 and Value of c is 3

Example 2: 

Javascript




// Defining underscore contrib variable
var _ = require('underscore-contrib'); 
  
function gfgFunc(a, b) {
    return b + " is " + a;
}
  
var gfg = _.flip2(gfgFunc);
  
console.log(gfg("GeeksforGeeks",+
   "Computer Science Portal for Geeks"));


Output:

GeeksforGeeks is Computer Science Portal for Geeks

Like Article
Suggest improvement
Share your thoughts in the comments

Similar Reads