proposal: let in if parentheses

Isiah Meadows isiahmeadows at gmail.com
Tue Aug 21 18:17:04 UTC 2018


It's possible, but the ability to optionally destructure is what would make
this feature worth it - I feel this should wait for pattern matching to be
added first, though.

On Tue, Aug 21, 2018 at 11:10 Jordan Harband <ljharb at gmail.com> wrote:

> ```
> {
>   let a = b();
>   if (a) {
>     c(a);
>   }
> }
> ```
>
> On Tue, Aug 21, 2018 at 10:54 AM, Ali Rahbari <rahbari at gmail.com> wrote:
>
>> while it's possible to use let keyword in for loop parentheses, it's not
>> possible to use it in if parentheses.
>>
>> There are two use cases for this:
>>
>> *1- if (let a = b()) a.c();*
>>  this can be done using optional chaining which is proposed:
>> b()?.c();
>>
>> *2- if (let a = b()) c(a);*
>> this or more sophisticated patterns can't be done in any way other than
>> this:
>> let a = b();
>> if (a) c(a);
>>
>> the problem here beside more line of codes, is *a *is defined outside of
>> if scope.
>>
>>
>> _______________________________________________
>> es-discuss mailing list
>> es-discuss at mozilla.org
>> https://mail.mozilla.org/listinfo/es-discuss
>>
>>
> _______________________________________________
> 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/a6e2f60a/attachment.html>


More information about the es-discuss mailing list