我已经阅读了一些关于函数currying的文档,所有文档都通过'currying'来反映'封闭'。所以,我怀疑如何区分封闭和currying?
已经在这里完成,并且没有任何明确的回答Does curry function in javascript uses principle of closure?
以下代码
var greet = function(greeting, name) {
console.log(greeting + ", " + name);
};
greet("Hello", "world"); //"Hello, world"
改写为(currying)(但是,据我所知,下面的代码是'封闭')
var greetCurried = function(greeting) {
return function(name) {
console.log(greeting + ", " + name);
};
};
这是我得到的结果:
var greetHello = greetCurried("Hello");
greetHello("World!"); //"Hello, World!"
greetHello("Universe!"); //"Hello, Universe!"
上面的代码代表'闭包'。如果是这样,我怎么能区分关闭和currying呢?
如何在javascript中区分闭包和currying