You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This change assumes loop blocks have scope (they do in ES6), which means
it "fixes" (i.e. changes) the pre-ES6 behaviour of `const` declarations
within loops. Whilst this is "correct", it differs from the previous
behaviour and so early JS engines that previously returned "incorrect"
results will now return "correct" results: specifically `const` in a
loop is local and can be deferenced in a callback with it's loop value
rather than it's terminal value.
This change affects NodeJS versions before 6.x, Chrome until approx v48,
Safari 9 and possibly 10 (I've not verified which browser versions are
actually affected). These engine will run generate "correct" ES6 results
for loops like:
```
async function nop(x) { return x }
var resolve,p = new Promise(function(r){resolve = r}) ;
var i = 0, x = 0, s = 1 ;
while (i<5) {
const j = i+1 ;
await nop() ;
setTimeout(function(){
x += 1 ;
s *= j ; // REFERS to "j"
if (x===5) {
resolve(s) ;
}
}, 0);
i++ ;
}
return await p ;
```
0 commit comments