I hadn't though about rest and how it passes multiple values to a function -- so it's definitely not an operator. I would say that since spread/rest syntax doesn't always evaluate to exactly one value, is context-specific (you can't use it standalone), and isn't defined as an operator in the ECMAScript spec with productions only ever containing *literally* ..., I can say definitively that it's not an operator.
On Wed, Jul 5, 2017 at 7:59 AM, T.J. Crowder < [email protected]> wrote: > You're not alone in this question; early on, lots of folks called `...` an > operator. It isn't. Rest and spread are syntax, just like the commas in a > function's parameter declaration list are syntax, not the comma operator. > What rest and spread do is outside the realm of what an operator can do. An > operator has a *single* result value which is (optionally) used where the > operator's expression was once the expression has been evaluated. E.g., in > `foo(2 * 5)`, the `2 * 5` is evaluated and the resulting value (`10`) is > passed into `foo` as the first argument. Roughly speaking, operators are > built-in functions with A) optionally-symbolic names, B) infix notation > (for binary and ternary operators), and C) lazy argument evaluation; and > like functions, they have only a single result value (and potential > side-effects). Rest and spread can't be expressed that way. Consider > `foo(...a)`. There's no single result value there, there's a series of > discrete values used as discrete arguments to `foo`. > > -- T.J. Crowder > > On Wed, Jul 5, 2017 at 1:40 PM, Andrew Li <[email protected]> wrote: > >> It seems as if there's two different ways to refer to the ... punctuator. >> How should I refer to this: >> >> const foo = [bar, ...baz]; >> >> MDN seems to suggest it's referred to as 'spread syntax' but its article >> URL seems to suggest it was initially created under the name 'spread >> operator' -- and it's more popular when looking at Google results. Syntax >> is the 'form' of the language while operators are generally used to perform >> a certain operation on a number of operands to produce a value. >> >> It seems as if on the surface, 'operator' is the most appropriate fit >> here, as it's seems more like a prefix unary operator more than it is >> syntax. But in the context of ECMAScript, it's not listed as an operator at >> MDN nor explicitly in the language specification -- and it's more of an >> extension of array literal syntax and only works in context of array >> literals. I would say it's more appropriately named syntax due to that, in >> the language specification, it's only ever mentioned literally in the >> ArgumentList and SpreadELement productions. That seems to suggest it's more >> just syntax rather than a standalone operator such as + or *. >> >> Which way of referring to it would be more 'correct' if any and is my >> reasoning correct? >> >> _______________________________________________ >> es-discuss mailing list >> [email protected] >> https://mail.mozilla.org/listinfo/es-discuss >> >> >
_______________________________________________ es-discuss mailing list [email protected] https://mail.mozilla.org/listinfo/es-discuss

