https://issues.dlang.org/show_bug.cgi?id=21929
--- Comment #3 from deadalnix <[email protected]> --- (In reply to Vladimir Panteleev from comment #1) > In JavaScript: > > [...] > > So, I don't think D's behavior is unexpected compared to other languages. > > Note that if you change "var" to "let" in JS then it behaves closer as to > what you may expect. > > At this point this is part of the language and is not a bug, so I don't > think the bugtracker is the proper place to post this. > > The workaround in D is the same as in JavaScript (before "let"), pass the > mutable values to the lambda so that their current values become part of the > lambda's state (or create an outer lambda which does this). This code is erroneous. In JS, var declare a variable at the function scope level. Try again declaring the variable using `let`, which creates a properly scoped variable in JS and see how it goes. --
