Underscore.js _.rcurry3() 方法
Underscore.js _.rcurry3() 方法返回给定函数的柯里化版本,其中从右到左最多处理三个参数。
句法:
_.rcurry3( fun )
参数:此方法采用上面列出并在下面讨论的单个参数:
- fun:这是作为参数传递的给定函数。
返回值:此方法返回一个柯里函数。
注意:要执行以下示例,您必须使用此命令提示符安装underscore-contrib库并执行以下命令。
npm install underscore-contrib
示例 1:
// Defining underscore contrib variable
var _ = require('underscore-contrib');
// Function
function div(a, b, c) {
return a/b/c;
}
var curried = _.rcurry3(div);
console.log("Curried division is :",
curried(4)(16)(256));
输出:
Curried division is : 4
示例 2:
// Defining underscore contrib variable
var _ = require('underscore-contrib');
// Function
function sub(a, b, c) {
return a-b-c;
}
var curried = _.rcurry3(sub);
console.log("Curried Subtraction is :",
curried(2)(4)(200));
输出:
Curried Subtraction is : 194
示例 3:颠倒的参数是:
// Defining underscore contrib variable
var _ = require('underscore-contrib');
// Function
function div(a, b, c) {
return ("a="+a+" and b="+b+" and c="+c);
}
var curried = _.rcurry3(div);
console.log(curried("a")("b")("c"));
输出:
a=c and b=b and c=a