Skip to content

Discussing about let & const support #1053

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
srenault opened this issue Nov 4, 2014 · 3 comments
Closed

Discussing about let & const support #1053

srenault opened this issue Nov 4, 2014 · 3 comments
Labels
Question An issue which isn't directly actionable in code

Comments

@srenault
Copy link

srenault commented Nov 4, 2014

Recently, you offer us let and const support. Sadly, the only way to use it is to target es6.
Why don't implement the logic in the compiler itself like others es6 features (class, arrow functions).
Does the reason is technical ?

@RyanCavanaugh RyanCavanaugh added the Question An issue which isn't directly actionable in code label Nov 4, 2014
@DanielRosenwasser
Copy link
Member

There actually are semantic differences with let/const that prevent us from just performing compile-time verification and turning them into vars. For example, take the following two code samples:

for (let i = 0; i < 5; i++) {
    setTimeout(() => console.log(i), 200);
}
for (var i = 0; i < 5; i++) {
    setTimeout(() => console.log(i), 200);
}

The only difference is the use of let vs var. The latter is a notorious example of how closure capture can be counter-intuitive in ECMAScript, where you'll just get:

5
5
5
5
5

On the other hand, the let example will give you the "expected" behavior:

0
1
2
3
4

We could support it, but the codegen isn't always the prettiest, and causes a perf-impact. We'd like to first get ES6 parity before we prioritize down-level support.

@joewood
Copy link

joewood commented Jan 17, 2015

Is this issue being tracked elsewhere? I'm wondering how Traceur handles this problem. ES6 support for let and const still seem inconsistent.

@basarat
Copy link
Contributor

basarat commented Jan 19, 2015

More technical discussion around let: #1690

Closure creation is how 6to5 and traceur handle it, and it does result in memory bloat even for them.

@microsoft microsoft locked and limited conversation to collaborators Jun 18, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Question An issue which isn't directly actionable in code
Projects
None yet
Development

No branches or pull requests

5 participants