Closed
Bug 1233089
Opened 10 years ago
Closed 10 years ago
Block scoping with let in for of loops
Categories
(Core :: JavaScript Engine, defect)
Core
JavaScript Engine
Tracking
()
RESOLVED
DUPLICATE
of bug 449811
People
(Reporter: PatrickWesterhoff, Unassigned)
Details
The `let` statement is supposed to create a block scope variable, so that we can write the following code:
let fs = [];
for (let i = 0; i < 3; i++) {
fs.push(() => i);
}
console.log(fs.map(f => f())); // 0, 1, 2
This works correctly with Firefox. However, when combining the `let` statement with the `for…of` loop, it does no longer work. Instead we get the same result as if we used `var` instead:
fs = [];
let nums = [0, 1, 2];
for (let i of nums) {
fs.push(() => i);
}
console.log(fs.map(f => f())); // 2, 2, 2
In V8, this seems to work fine (via Node 4.x), and it also works in Babel. What is causing this incorrect behavior of let in for…of loops in Firefox?
Updated•10 years ago
|
Status: UNCONFIRMED → RESOLVED
Closed: 10 years ago
Resolution: --- → DUPLICATE
You need to log in
before you can comment on or make changes to this bug.
Description
•