📜  Underscore.js _.flip2() 方法

📅  最后修改于: 2022-05-13 01:56:36.385000             🧑  作者: Mango

Underscore.js _.flip2() 方法

_.flip2()方法返回一个与给函数函数工作相同但以相反顺序接受前两个参数的函数。所有其余参数的顺序保持不变。

句法:

_.flip2( function );

参数:此方法接受一个带有一些参数的函数。

返回值:此方法返回一个函数。

注意:这在普通 JavaScript 中不起作用,因为它需要安装 underscore.js contrib 库。

underscore.js contrib 库可以使用npm install underscore-contrib –save 安装。

示例 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));


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"));


输出:

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

示例 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"));

输出:

GeeksforGeeks is Computer Science Portal for Geeks