<div dir="ltr">I like the idea, and I generally agree that your proposal would increase readability, but I'm not a fan of the colon in parenthesis.<div>In this context, the colon looks like it should represent a member assignment of 'b' to 'a'.</div><div><br></div></div><div class="gmail_extra"><br clear="all"><div><div class="gmail_signature" data-smartmail="gmail_signature">-Ryan Birmingham<br></div></div>
<br><div class="gmail_quote">On 1 February 2017 at 11:27, Felipe Nascimento de Moura <span dir="ltr"><<a href="mailto:felipenmoura@gmail.com" target="_blank">felipenmoura@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div dir="ltr" class="m_7816404750273057735gmail_msg">Hi.<div class="m_7816404750273057735gmail_msg"><br class="m_7816404750273057735gmail_msg"></div><div class="m_7816404750273057735gmail_msg">I wonder if there is already a proposal for such thing or if it would be something interesting to be proposal:</div><div class="m_7816404750273057735gmail_msg"><br class="m_7816404750273057735gmail_msg"></div><div class="m_7816404750273057735gmail_msg"><b class="m_7816404750273057735gmail_msg">The motivation:</b></div><div class="m_7816404750273057735gmail_msg">Let's say you have an object whose property you want to compare to 'a' or 'b':</div><div class="m_7816404750273057735gmail_msg"><br class="m_7816404750273057735gmail_msg"></div><div class="m_7816404750273057735gmail_msg">```</div><div class="m_7816404750273057735gmail_msg"><div class="m_7816404750273057735gmail_msg">if (object.property.secondProp === 'a' || object.property.secondProp === 'b') {</div><div class="m_7816404750273057735gmail_msg">  // do something</div><div class="m_7816404750273057735gmail_msg">}</div><div class="m_7816404750273057735gmail_msg">```</div><div class="m_7816404750273057735gmail_msg"><br class="m_7816404750273057735gmail_msg"></div><div class="m_7816404750273057735gmail_msg"><b class="m_7816404750273057735gmail_msg">The proposal:</b></div><div class="m_7816404750273057735gmail_msg">Now, with this syntax you would be able to perform such comparisons in a much simpler, better to read approach:</div><div class="m_7816404750273057735gmail_msg"><br class="m_7816404750273057735gmail_msg"></div><div class="m_7816404750273057735gmail_msg">```</div><div class="m_7816404750273057735gmail_msg">if (object.property.secondProp === ('a' : 'b')) {</div><div class="m_7816404750273057735gmail_msg">    // do Something</div><div class="m_7816404750273057735gmail_msg">}</div><div class="m_7816404750273057735gmail_msg">```<br class="m_7816404750273057735gmail_msg"></div><div class="m_7816404750273057735gmail_msg"><br class="m_7816404750273057735gmail_msg"></div><div class="m_7816404750273057735gmail_msg">And with the advance of the <a href="https://github.com/claudepache/es-optional-chaining" class="m_7816404750273057735gmail_msg" target="_blank">Optional Chaining Operator</a> proposal, it would get even better, like so:</div><div class="m_7816404750273057735gmail_msg"><br class="m_7816404750273057735gmail_msg"></div><div class="m_7816404750273057735gmail_msg"><div class="m_7816404750273057735gmail_msg">```</div><div class="m_7816404750273057735gmail_msg">// this:</div><div class="m_7816404750273057735gmail_msg">if (object &&</div><div class="m_7816404750273057735gmail_msg">    object.property &&</div><div class="m_7816404750273057735gmail_msg">    (object.property.secondProp === 'a' ||</div><div class="m_7816404750273057735gmail_msg">    object.property.secondProp === 'b')<span class="m_7816404750273057735inbox-inbox-Apple-converted-space">) </span>{</div><div class="m_7816404750273057735gmail_msg">  // ...</div><div class="m_7816404750273057735gmail_msg">}</div><div class="m_7816404750273057735gmail_msg"><br class="m_7816404750273057735gmail_msg"></div><div class="m_7816404750273057735gmail_msg">// becomes this:</div><div class="m_7816404750273057735gmail_msg">if (object?.property?.secondProp === ('a' : 'b')) { ... }</div><div class="m_7816404750273057735gmail_msg">```<br class="m_7816404750273057735gmail_msg"></div></div><div class="m_7816404750273057735gmail_msg"><br></div><div class="m_7816404750273057735gmail_msg"><b>Alternatives:</b></div><div class="m_7816404750273057735gmail_msg">I do know that we could accomplish that with other techniques, like:</div><div class="m_7816404750273057735gmail_msg"><br></div><div class="m_7816404750273057735gmail_msg">```</div><div class="m_7816404750273057735gmail_msg">['a', 'b'].includes(object.property.<wbr>secondProp)<br></div><div class="m_7816404750273057735gmail_msg">```</div><div class="m_7816404750273057735gmail_msg"><br class="m_7816404750273057735gmail_msg"></div><div class="m_7816404750273057735gmail_msg">I just think it might be counterintuitive and having a syntax for a "short comparing" would be better for reading and understanding.</div><div class="m_7816404750273057735gmail_msg"><br></div><div class="m_7816404750273057735gmail_msg">Would make ternary comparison even shorter, too:</div><div class="m_7816404750273057735gmail_msg"><br></div><div class="m_7816404750273057735gmail_msg">```</div><div class="m_7816404750273057735gmail_msg">let currentState = object.property.status === ('fail' : 'ok') ? 'done' : 'doing'</div><div class="m_7816404750273057735gmail_msg">```</div><div class="m_7816404750273057735gmail_msg"><br></div><div class="m_7816404750273057735gmail_msg">Please let me hear your thoughts on that :)</div><div class="m_7816404750273057735gmail_msg"><br></div><div class="m_7816404750273057735gmail_msg">Regards.</div><div class="m_7816404750273057735gmail_msg"><br class="m_7816404750273057735gmail_msg"></div><div class="m_7816404750273057735gmail_msg"><br class="m_7816404750273057735gmail_msg"></div><div class="m_7816404750273057735gmail_msg"><br class="m_7816404750273057735gmail_msg"></div><div class="m_7816404750273057735gmail_msg"><br class="m_7816404750273057735gmail_msg"></div><div style="font-weight:bold" class="m_7816404750273057735gmail_msg"><br class="m_7816404750273057735gmail_msg"></div></div><div style="font-weight:bold" class="m_7816404750273057735gmail_msg"><br class="m_7816404750273057735gmail_msg"></div></div></div>
<br>______________________________<wbr>_________________<br>
es-discuss mailing list<br>
<a href="mailto:es-discuss@mozilla.org">es-discuss@mozilla.org</a><br>
<a href="https://mail.mozilla.org/listinfo/es-discuss" rel="noreferrer" target="_blank">https://mail.mozilla.org/<wbr>listinfo/es-discuss</a><br>
<br></blockquote></div><br></div>