9.5.1 for loop
const works like var, but you can't change the initial value of a const-declared variable.
I think here should be 'const works like let'.
9.5.2 for-of loop and for-in loop
let arr = [];
for (let i of [0, 1, 2]) {
arr.push(() => i);
}
arr.map(x => x()); // [0,1,2]
In latest firefox developer edition, the result is [2, 2, 2].
in the latest Chrome dev, the result is expected:
(function () {
'use strict'
let arr = []
for (let i of [0, 1, 2]) {
arr.push(function () {
return i
})
}
let r = arr.map(function (x) {
return x()
})
console.log(r) // [0, 1, 2]
}())