Thursday, 1 September 2016

How to understand closures in Javascript?

How can one understand closures in Javascript?




In general terms, a closure is a function bound to one or more external variables. When it is called, the function is able to access these variables. In JavaScript, closures are often implemented when functions are declared inside another function. The inner function accesses variables of the parent one, even after the parent function has terminated




In this statement, "a closure is a function bound to one or more external variables", does it mean we can do this : var myFun = Function(msg){...}; is it correct ?




What does it mean "even after the parent function has terminated"?

No comments:

Post a Comment

c++ - Does curly brackets matter for empty constructor?

Those brackets declare an empty, inline constructor. In that case, with them, the constructor does exist, it merely does nothing more than t...