-
哔哔one
最简单最完美实现// es6 const mul = (x) => { let sum = x let curried = (y) => { sum = sum * y return curried } curried.toString = () => sum return curried } console.log(mul(1)) //1 console.log(mul(1)(2))//2 console.log(mul(1)(2)(3))//6 console.log(mul(1)(2)(3)(4))//24 ... // es5 function mul(x){ var sum = x var curried = function(y){ sum = sum * y return curried } curried.toString=function(){ return sum } return curried} console.log(mul(1)) //1 console.log(mul(1)(2))//2 console.log(mul(1)(2)(3))//6 console.log(mul(1)(2)(3)(4))//24 ...
-
HUWWW
var f = (function() { let r = 1; return function f(...args){ r *= args.reduce((p, n) => p * n); f.valueOf = () => r; return f; }}());f(3)(4)(4)
-
翻阅古今
const a = () => () => () => 48
-
斯蒂芬大帝
var a = function(x) { return function(y) { return function(z) { console.log(x * y * z); return x * y * z; }; };};
-
吃鸡游戏
Function CurryingSimple, Beautiful, Interestingfunction curry(fn, ...args){ return args.length === fn.length ? fn(...args) : (...next_args) => curry(fn, ...args, ...next_args); }Nextfunction mul(a, b, c){ return a * b * c; }// mul(3, 4, 4); => 48 let a = curry(mul); a(3)(4)(4); // => 48 a(3, 4, 4); // => 48 a(3)(4, 4); // => 48 a()()()()()(3, 4)(4); // => 48 S
-
www说
let total;function a(m){ total = m; return function(n){ return a(m*n) }}a(3)(4)(4)console.log(total) //48