How can I make var a = add(2)(3); //5 work?

后端 未结 28 2376
长发绾君心
长发绾君心 2020-11-27 14:11

I want to make this syntax possible:

var a = add(2)(3); //5

based on what I read at http://dmitry.baranovskiy.com/post/31797647

I\

28条回答
  •  萌比男神i
    2020-11-27 14:39

    Simply we can write a function like this

        function sum(x){
          return function(y){
            return function(z){
              return x+y+z;
            }
          }
        }
    
        sum(2)(3)(4)//Output->9
    

提交回复
热议问题