Because C (B, BCPL, Algol). Too late to change JS where people do tricks
such as !-x. No win in risking compat break.

/be
On Fri, Sep 25, 2015 at 4:18 AM Herby Vojčík <he...@mailbox.sk> wrote:

>
>
> Herby Vojčík wrote:
> >
> >
> > Claude Pache wrote:
> >>
> >> I just wonder why it is important that unary binds tighter? For
> >> instance, before I carefully studied the issue of this thread, I have
> >> never expected that unary minus binds tighter than binary multiplication
> >> operator in expressions like `-2*x` (although it does not matter in that
> >> case).
> >>
> >> Making the parentheses mandatory here will be somewhat annoying in
> >> perfectly reasonable expressions, where you usually don’t use
> >> parentheses in real math notation., like:
> >> ```
> >> let s2 = - x**2 - y**2 - z**2 + t**2
> >> ```
> >
> > I would overcome it and do not write the parens:
> >
> > let s2 = 0 - x**2 - y**2 - z**2 + t**2
>
> An off-topic thought: Unary minus (and plus) are only used with numbers
> in JS. Why are they treated specially, not as hidden 0+x and 0-x,
> respectively? That would be logical (unary plus and minus would have
> same precendence as binary plus and minus).
>
> > Writing mandatory parens here is ugly.
> >
> > In fact, I am surprised "-2" is unary minus with 2, I thought it is
> > number -2. And similarly to Claude, I always read -x*y in math notation,
> > that is, as -(x*y). Luckily, for multiplication it does not matter.
> >
> > Herby
> > _______________________________________________
> > 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