如何使var a = add(2)(3); // 5工作? [英] How can I make var a = add(2)(3); //5 work?
本文介绍了如何使var a = add(2)(3); // 5工作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想使这种语法成为可能:
I want to make this syntax possible:
var a = add(2)(3); //5
基于我在 http://dmitry.baranovskiy.com/post/31797647
我没有如何使它成为可能。
I've got no clue how to make it possible.
推荐答案
你需要添加一个带参数的函数并返回一个函数将参数添加到add和self的参数。
You need add to be a function that takes an argument and returns a function that takes an argument that adds the argument to add and itself.
var add = function(x) {
return function(y) { return x + y; };
}
这篇关于如何使var a = add(2)(3); // 5工作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文