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

后端 未结 28 2439
长发绾君心
长发绾君心 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条回答
  •  青春惊慌失措
    2020-11-27 15:00

    Arrow functions undoubtedly make it pretty simple to get the required result:

    const Sum = a => b => b ? Sum( a + b ) : a;
    
    console.log(Sum(3)(4)(2)(5)()); //14
    
    console.log(Sum(3)(4)(1)()); //8
    

提交回复
热议问题