Skip to content

An issue about let statement in typescript. #6356

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
arliang opened this issue Jan 5, 2016 · 2 comments
Closed

An issue about let statement in typescript. #6356

arliang opened this issue Jan 5, 2016 · 2 comments
Labels
Duplicate An existing issue was already created

Comments

@arliang
Copy link

arliang commented Jan 5, 2016

http://www.typescriptlang.org/Playground#src=for(let%20i%20%3D%200%3B%20i%20%3C%2010%3B%20i%2B%2B)%7B%0D%0A%09setTimeout(function()%7B%0D%0A%09%09console.log(i)%3B%0D%0A%09%7D)%3B%0D%0A%7D

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);
}
@RyanCavanaugh
Copy link
Member

This has already been implemented in #5208

@RyanCavanaugh
Copy link
Member

Duplicate #3915

@RyanCavanaugh RyanCavanaugh added the Duplicate An existing issue was already created label Jan 5, 2016
@microsoft microsoft locked and limited conversation to collaborators Jun 19, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Duplicate An existing issue was already created
Projects
None yet
Development

No branches or pull requests

2 participants