📜  Lodash _.curryRight3() 方法

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

Lodash _.curryRight3() 方法

Lodash 是一个基于 underscore.js 的 JavaScript 库。 Lodash 有助于处理数组、字符串、对象、数字等。

_.curryRight3() 方法返回给定函数的柯里化版本,其中从右到左最多处理三个参数。

句法:

_.curryRight3( fun )

参数:此方法采用上面列出并在下面讨论的单个参数:

  • fun:这是柯里化版本中应该使用的函数。

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

注意:此方法在普通 JavaScript 中不起作用,因为它需要安装 Lodash contrib 库。可以使用npm install lodash-contrib –save 安装 lodash- contrib 库

npm install lodash-contrib

示例 1:

Javascript
// Defining lodash contrib variable
var _ = require('lodash-contrib'); 
  
// Function to curry
function div(a, b, c) {
    return a / b / c;
}
  
var curried = _.curryRight3(div);
  
console.log("Curried division is :",
    curried(4)(32)(1000));


Javascript
// Defining lodash contrib variable
var _ = require('lodash-contrib'); 
  
// Function
function div(a, b, c) {
    return a / b / c;
}
  
var curried = _.curryRight3(div);
  
console.log("Curried division is :",
    curried(4)(1000)(10));


Javascript
// Defining lodash contrib variable
var _ = require('lodash-contrib'); 
  
// Function
function sub(a, b, c) {
    return a - b - c;
}
  
var curried = _.curryRight3(sub);
  
console.log("Curried Subtraction is :",
    curried(2)(10)(1000));


Javascript
// Defining lodash contrib variable
var _ = require('lodash-contrib'); 
  
// Function
function div(a, b, c) {
    return ("a=" + a + " and b=" + b +
            " and c=" + c);
}
  
var curried = _.curryRight3(div);
  
console.log(curried("a")("b")("c"));


输出:

Curried division is : 7.8125

示例 2:

Javascript

// Defining lodash contrib variable
var _ = require('lodash-contrib'); 
  
// Function
function div(a, b, c) {
    return a / b / c;
}
  
var curried = _.curryRight3(div);
  
console.log("Curried division is :",
    curried(4)(1000)(10));

输出:

Curried division is : 0.0025

示例 3:

Javascript

// Defining lodash contrib variable
var _ = require('lodash-contrib'); 
  
// Function
function sub(a, b, c) {
    return a - b - c;
}
  
var curried = _.curryRight3(sub);
  
console.log("Curried Subtraction is :",
    curried(2)(10)(1000));

输出:

Curried Subtraction is : 988

示例 4:

Javascript

// Defining lodash contrib variable
var _ = require('lodash-contrib'); 
  
// Function
function div(a, b, c) {
    return ("a=" + a + " and b=" + b +
            " and c=" + c);
}
  
var curried = _.curryRight3(div);
  
console.log(curried("a")("b")("c"));

输出:

a=c and b=b and c=a