Basics
Closures
A closure is the combination of a function and lexical environment which that function was declared. It executes with the scope that was defined in place, not with the state that's in place when it is executed. A function with lexical scope is able to access variables that were defined in the parent scope.
When we redefine a new
say
variable, it doesn't change the state of the first scope ofprepareBark()
Why would you use one?
Data privacy / emulating private methods with closures. Commonly used in the module pattern.
References
Last updated