前端开发 2016-12-13
function count(a){ return function(b){ return a*b; } } // count(1)(2) function count(a){ return function(b){ return function(c){ return a*b*c; }; } } // count(1)(2)(4) // 根据规律改进 ,只能做到count(1)(3)(7)()这一步了,能力达不到~~ function count(a){ var cc = function(x){ if(!arguments.length) return a; return count(a*x) } return cc; }
count(1)(3) -- function 3 差一点
function count(x){ var fn = function(y){ return count(x*y); } fn.toString = function(){ return x; }; return fn; } console.log( count(1)(2)(4) ) // function 8 console.log( (count(1)(2)(4)).toString() ); // 8
var getWife = currying(function() { var allWife = [].slice.call(arguments); console.log(allWife.join(";")); }, "0");
getWife(1, 2, 3, 4, 5) // 0;1;2;3;4;5 ```