4 ms·
This might as well be titled "Understand mutable variables (and function-scoping)". The post doesn't really explain closures, and the examples really just show
by reycharles 13y ago
This might as well be titled "Understand mutable variables (and function-scoping)".
The post doesn't really explain closures, and the examples really just show what happens when you mutate variables, in this case in a for-loop - they change value!
The last example also shows how javascript has function scope as opposed to block scope, i.e. the variable "string" might as well have been declared outside the for-loop.
- christian_fei 13y agoWhat's wrong with mutable variables and closures? I 'seal' the variable value 'i' into a closure, isn't that a good example for a closure? I repeat, I wrote this to get constructive feedback, so thanks, and I would like to discuss this further
- christian_fei 13y agoWhat is the best definition of a closure?