📜  Underscore.js _.flip() 方法

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

Underscore.js _.flip() 方法

_.flip()方法返回一个与给函数函数工作相同但以相反顺序接受参数的函数。

句法:

_.flip( 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 = _.flip(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 = _.flip(gfgFunc);
  
console.log(gfg("GeeksforGeeks",+
    "Computer Science Portal for Geeks"));


输出:

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



示例 2:

Javascript

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

输出:

GeeksforGeeks is Computer Science Portal for Geeks