On Fri, Sep 16, 2016 at 2:43 AM, Bob Myers <r...@gol.com> wrote:

> I often find myself wanting to do this in the case of `while`. I've been
> writing
>
> ```
> for (let a; a = someLongCondition();) { doSomethingWith(a); }
> ```
>
> In that spirit, an oddball proposal:
>
> ```
> while (let a = someLongCondition(); a) { ...use a... }
> if (let a = someLongCondition(); a) { ...use a... }
>

switch( let a = something() ) {   }

would   ' do { ... use a ... } while( let a = f() ); '  work?

( (let a = f() ) > 3 ) ? (a-3) : (a+3)     //ternary operator?

which begins to look like   '( [let/var/const] ... ) '  in any expression.


```
>
> On Fri, Sep 16, 2016 at 2:39 AM, Isiah Meadows <isiahmead...@gmail.com>
> wrote:
>
>> I say let's hold off until JavaScript gets pattern matching support
>> (assuming it does). It's rather limiting otherwise, and the use case IMHO
>> doesn't really merit a new syntax for it.
>>
>> On Thu, Sep 15, 2016, 15:47 Jeremy Martin <jmar...@gmail.com> wrote:
>>
>>> > If yes ... why would anyone write that ?
>>>
>>> I think it would have to be "yes" (and that's probably just a contrived
>>> example that doesn't demonstrate the usefulness).
>>>
>>> Slightly less contrived, I could see the value in this, though. E.g.,
>>>
>>> ```
>>> router.get('/user', (req, res, next) => {
>>>     if (let user = req.session.user) {
>>>         // do stuff with user here
>>>     } else {
>>>         res.status(401).end();
>>>     }
>>> });
>>> ```
>>>
>>> I don't think it works as cleanly with `var`, but `const` and `let` has
>>> some nice precedence with for-statements.
>>>
>>>
>>> On Thu, Sep 15, 2016 at 2:45 PM, Andrea Giammarchi <
>>> andrea.giammar...@gmail.com> wrote:
>>>
>>>> > if( let a = ( let b = 10 ) * 3 > 10 )
>>>>
>>>> I've honestly no idea, at first/quick read, what the hell that would
>>>> produce.
>>>>
>>>> Is `a` going to be just `true` ? 'cause if not, this proposal violates
>>>> operator precedence.
>>>>
>>>> If yes ... why would anyone write that ?
>>>>
>>>> On Thu, Sep 15, 2016 at 7:30 PM, J Decker <d3c...@gmail.com> wrote:
>>>>
>>>>> Why not more generally - allow let/var declarations in expressions?
>>>>>
>>>>> coming from a long and rich C background, I have no issues with the
>>>>> existing mechanisms... but for those languages that do support variable
>>>>> declarations in for loops; I've always wondered why not any expression?
>>>>>
>>>>> if( let a = ( let b = 10 ) * 3 > 10 )
>>>>> ... or ...
>>>>>
>>>>> c = (let a = b*d)
>>>>>
>>>>> granted, the scope is extremely limited in the last case...
>>>>>
>>>>> _______________________________________________
>>>>> es-discuss mailing list
>>>>> es-discuss@mozilla.org
>>>>> https://mail.mozilla.org/listinfo/es-discuss
>>>>>
>>>>>
>>>>
>>>> _______________________________________________
>>>> es-discuss mailing list
>>>> es-discuss@mozilla.org
>>>> https://mail.mozilla.org/listinfo/es-discuss
>>>>
>>>>
>>>
>>>
>>> --
>>> Jeremy Martin
>>> 661.312.3853
>>> http://devsmash.com
>>> @jmar777
>>> _______________________________________________
>>> es-discuss mailing list
>>> es-discuss@mozilla.org
>>> https://mail.mozilla.org/listinfo/es-discuss
>>>
>>
>> _______________________________________________
>> es-discuss mailing list
>> es-discuss@mozilla.org
>> https://mail.mozilla.org/listinfo/es-discuss
>>
>>
>
> _______________________________________________
> es-discuss mailing list
> es-discuss@mozilla.org
> https://mail.mozilla.org/listinfo/es-discuss
>
>
_______________________________________________
es-discuss mailing list
es-discuss@mozilla.org
https://mail.mozilla.org/listinfo/es-discuss

Reply via email to