[Issue 21929] delegates capture do not respect scoping
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Tue May 18 19:47:17 UTC 2021
https://issues.dlang.org/show_bug.cgi?id=21929
--- Comment #3 from deadalnix <deadalnix at gmail.com> ---
(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.
--
More information about the Digitalmars-d-bugs
mailing list