Closed
Description
for(let i = 0; i < 3; i++){
setTimeout(function(){
console.log(i);
});
}
for (var i = 0; i < 3; i++) {
setTimeout(function () {
console.log(i);
});
}
In es6, the first example outputs 0 1 2
But the JS which translated by TS outputs 3 3 3
It would act like es6 if wrapped with (function(i){ /* */ })(i)
for (var i = 0; i < 10; i++) {
(function(i){
setTimeout(function () {
console.log(i);
});
})(i);
}