proposal: let in if parentheses
Isiah Meadows
isiahmeadows at gmail.com
Tue Aug 21 19:27:04 UTC 2018
Anything beyond the last variable shouldn't be returned - anything else
would be exceedingly unexpected. Note that in terms of completions, they
all currently return `undefined` when you `eval` them, but for `if (let
...)` and `while (let ...)`, I would expect that it'd work similarly to
sequence expressions.
On Tue, Aug 21, 2018 at 12:08 Ali Rahbari <rahbari at gmail.com> wrote:
> The problem with let, const or var is you can define multiple variable
> after them, and it's ambiguous which one must be returned from the
> expression. But like comma expression which would return the last part as a
> result, the let and const also should return the last assignment as the
> result so it can be used inside parentheses
>
> (let a = 1, b = 2) === 2
>
> A common type of code in JS is searching for element and do something with
> them:
>
> let e1 = document.getElementById('id1');
> if (e1) this.AppendChild(e);
>
> let e2 = document.getElementById('id2');
> if (e2) this.AppendChild(e);
>
> This pattern can really help encapsulation and readability;
>
> if (let e = document.getElementById('id1')) this.AppendChild(e);
> if (let e = document.getElementById('id2')) this.AppendChild(e);
> _______________________________________________
> es-discuss mailing list
> es-discuss at mozilla.org
> https://mail.mozilla.org/listinfo/es-discuss
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20180821/b901515a/attachment.html>
More information about the es-discuss
mailing list