hi
I started the thread with this question because I thought exactly in both
performance (short circuit) and readability.
I got a little bit lost in this thread here...looks like there are some
other e-mails mixed to it!
But anyways, bear with me:
```
// the expression
let x = a || b;
// could be
let x;
if (a) { x = a; }
else { x = b; }
```
So...the operator "||" in THIS particular case is also just an alternative,
and yet extremely useful (and used). It is short, and is it beautiful for
reading.
That OR could be the good old "if"! Even though, I use it everywhere I can.
```
// the expression
if (obj.prop.prop2 === 'a' : 'b' : 'c') { ... }
// could be
if (obj.prop.prop2 === 'a' || obj.prop.prop2 === 'b' || obj.prop.prop2 ===
'c') { ... }
```
I see the same feeling here...yes, we could use other approaches, we could
use destructors using the keys of an object...we could use [].contains,
[].some, switch/case...but this is a much more beautiful way of doing it :)
I don't think it would make sense for &&, once things are not supposed to
be equal to two different values
Again, just a suggestion, but one thing I like in JavaScript is its
readability and power of "deduction power".
The first time I read a code using || in an assignment (and I had no idea
what that was, much younger, learning by myself, not knowing english, with
almost zero access to internet), it toke me about 5 seconds to "guess" its
behavior...it simply makes sense.
Thanks.
On Fri, Feb 3, 2017 at 6:50 PM Claude Pache <claude.pache at gmail.com> wrote:
>> > Le 3 févr. 2017 à 21:05, Bob Myers <rtm at gol.com> a écrit :
> >
> > If you're worried about short-circuiting, then
> >
> > ```
> > [() => a, () => b].some(x => c === x())
> > ```
>> Even shorter: `(_ => _ === a || _ === b )(c)`
>> But more seriously: Now you have another issue, namely readability.
>> —Claude
>> _______________________________________________
> 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/20170204/9013e5d6/attachment.html>