es-discuss Digest, Vol 82, Issue 98

raul mihaila raul.mihaila at gmail.com
Thu Dec 26 05:06:55 PST 2013


>
>
> ---------- Forwarded message ----------
> From: Brendan Eich <brendan at mozilla.com>
> To: raul mihaila <raul.mihaila at gmail.com>
> Cc: es-discuss <es-discuss at mozilla.org>
> Date: Wed, 25 Dec 2013 13:44:21 -0500
> Subject: Re: Fwd: local variables with inherited values
>


>
> That's unusual -- why would it take on the out same-named variable's
> value? Note it won't work for 'const', only 'let'. Is there any difference
> for 'let' between your proposal and A2, lexical window? Let's see, by
> simplifying the example to make the inner 'const x' into a 'let x':
>
>
 I misinterpreted Waldemar Horwant's cases. There's no difference between
my proposal and A2 + B2, besides a possible way to make it more readable.


> In any case, we aren't adding another keyword, and your approach does not
> work for 'const' at all. For 'let' or any new keyword, it hoists and
> implicitly initializes, which is too implicit and magical, even for JS.
>
>
You're right, it wouldn't work for const.


> It's far less readable, though, because of the implicit magic
> initialization from outer shadowed x. What if there is no outer x? And
> 'const' does not work at all. We can't have two values for a given 'const'
> binding.
>
>
I agree, if there's no way to make it more readable, it will be too magical
and bad. (BTW, throw if there's no outer x.) I am beginning to like the
syntax from ES4. I suppose it would work with multiple variables as well.
let (x = x, y = y, z = x + y /* maybe would work? */) {
    ....
}
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20131226/e57c21b7/attachment.html>


More information about the es-discuss mailing list