Shorter syntax for arrow function assignment

T.J. Crowder tj.crowder at farsightsoftware.com
Wed Oct 25 11:57:32 UTC 2017


On Tue, Oct 24, 2017 at 6:26 PM, dante federici
<c.dante.federici at gmail.com> wrote:
>
> So, something like:
> ```
> myFn() {
> }
> ```
>
> Would be considered as:
> ```
> var myFn = function() {
> }
> ```
>
> with what semantics exist now. Not best practices, but what is
> currently interpreted in the language.

No, it isn't. It's a `SyntaxError: Unexpected token {`. There's a big
difference between `myFn() { }` and `myFn = function() { };` The latter is
valid syntax for the horror of implicit globals (in loose mode; strict mode
fixed it). The former is just a syntax error. (It would be valid method
syntax if it were inside an object initializer or `class`.)

But AFAIK, Brian Blakely wasn't promoting that syntax anyway. His original
post only ever uses this shorthand with `export`, so I think it was meant
to be specific to exporting.

-- T.J. Crowder
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20171025/96b172d0/attachment-0001.html>


More information about the es-discuss mailing list