Jup das ist leider der einzige (möglichst simple) Weg. Andere möglichkeit wäre den Timeout auszulagern und den i zu übergeben. Aber ist halt leider so :/
Unser Bruder muss da echt los...
Conversation
Use `let` not `var`. I your brother worked hard to help get this into ES6, where it means that each iteration has its own binding environment, so the closure works as you want it to. Guten Abend!
5
8
42
I didn’t realize that. So JavaScript declaration-site distinctions between let and var are the analog of C++ lambda-site distractions between capture by variable or by value.
3
5
Of languages supporting mutability, only Haskell IORef t and ML t ref are voodoo-free in this tegard. There, identifiers are always bound to constants, and references must be explicitly read and written.
3
3
This highlights that in an imperative language, the default loop form should be something like “for(i in 1 to 10) ...” with the semantic that each iteration has a distinct x binding, and no need to explain away why the i’s before and after the i++ are different i’s.
1
6
i.e. C-style for loops are bad. I’ve been saying this to everyone who will listen for years. :)
3
8
isn't this also about by-value vs. by-reference closure conversion? I find it confusing that JS has both.
1
No, this isn't about that. Do you mean JS has both reference (object) and primitive (null undefined boolean number string) types? Thank Java for that one :-/. "Make it look like Java!"
2
2
It should not be observable in JS (outside of devtools and pathological var-aliases-formal-parameter+arguments[i] usage) whether an implementation uses env capture, binding capture, heap-boxing a la Chez Scheme, etc.
2
1
(The only way to observe the pathological cases would be by timing benchmarks, I hasten to add. No spec abstraction leak that I know of.)
1
And by observing garbage collection I'm guessing?
Always big fun for non-determinism hunters seeking bugs and leaks (timing channels).
1



