1. 粗暴版
// 简单版 function add(a) { return function (b) { return function (c) { return a + b + c; } } } console.log(add(1)(2)(3)); // 6
2. 参数长度固定
var add = function (m) { var temp = function (n) { return add(m + n); } temp.toString = function () { return m; } return temp;};console.log(add(3)(4)(5)); // 12console.log(add(3)(6)(9)(25)); // 43
3. 使用push方法
function currying() { let args = Array.prototype.slice(arguments) let res = function () { for (let i of arguments) { args.push(i) } return res } res.toString = function () { return args.reduce((a, b) => a + b) } return res } console.log(currying(1)(2)(3).toString());