1 | ;
|
2 | var arr = [];
|
3 |
|
4 | // fresh x per iteration so can't be transformed
|
5 | // note v8 bug https://code.google.com/p/v8/issues/detail?id=2560
|
6 | // also see other/v8-bug.js
|
7 | for (let x = 0; x < 10; x++) {
|
8 | arr.push(function() { return x; });
|
9 | }
|
10 |
|
11 | // fresh y per iteration so can't be transformed
|
12 | for (var x = 0; x < 10; x++) {
|
13 | let y = x;
|
14 | arr.push(function() { return y; });
|
15 | }
|
16 |
|
17 | // fresh x per iteration so can't be transformed
|
18 | for (let x in [0,1,2]) {
|
19 | arr.push(function() { return x; });
|
20 | }
|
21 |
|
22 | arr.forEach(function(f) {
|
23 | console.log(f());
|
24 | });
|