js柯里化

function sum(x){
    console.log('x:='+x);
     var y = function(x){ 
        console.log('xx:='+x);
        console.log('y:='+y);
          return sum(x+y) 
     }
     
     y.toString = y.valueOf = function(){ 
          return x; 
     } 
    console.log('yy:='+y);
     return y; 
} 
sum(1)(2)(3)(4);//10

 

posted @ 2017-03-03 14:16  Yuri_trender  阅读(140)  评论(0编辑  收藏  举报