Can someone please explain the reason and benefit why you might want to do this in your code?
There's no reason to do it when you'll always do it whenever calling the function (a
in your case). The reason in the general case is that the author of a
is allowing for the possibility you may not want to call the resulting function right away. So the a()();
case is just a special case of the general case of
var f = a();
// later...
f();
Also, is the function that returns 'hello' considered a closure?
Yes, technically, although in your example it doesn't have anything special to close over that a
doesn't already close over, since there are no arguments to a
or variables within a
.
More (on my anemic blog): Closures are not complicated
No comments:
Post a Comment