The Old New Thing

Closing over the loop variable is just as harmful in JavaScript as it is in C#, and more cumbersome to fix

Prerequisite reading: Closing over the loop variable considered harmful. JavaScript has the same problem. Consider: The most common case where you encounter this is when you are hooking up event handlers in a loop, so that's the case I used as an example. No matter which button you click, they all alert , rather than the respective ...