2013/11/29 Nick Krempel <[email protected]>
> Couldn't find anything on this in the archives, but is there a proposal
> for:
>
> if (let var = expr) {
> // var in scope
> }
> ...
> ("const" should also be OK in place of "let", at least for "if" and
> "switch".)
>
Thanks for taking this to the list. I was meaning to do it after a
discussion with Allen at Front-Trends earlier this year but never got
around to it, partly because Allen (correctly) suggested that it was almost
certainly too late for ES6. I back this also.
Another perspective of why this is a great feature: My ES6 programming is
const-first, meaning I only use let for bindings that change and const for
everything else. In practice over 90% of all my variables are const which
is great because the let's that are in there really stand out. The
unfortunate consequence of not being able to declare a variable inside the
if-condition (for example) is that it forces const's to let's.
I wanted to do
if (const val = compute(something)) {
// ...
}
but I had to do
let val;
if (val = compute(something)) {
// ...
}
which is unfortunate not only because val leaks to the outer scope but also
because let suggest that the binding mutates (which it technically does,
but practically doesn't).
/Olov
_______________________________________________
es-discuss mailing list
[email protected]
https://mail.mozilla.org/listinfo/es-discuss