Single destructuring argument to an arrow function

Rick Waldron waldron.rick at gmail.com
Fri Mar 20 19:27:33 UTC 2015


Inline...

On Thu, Mar 19, 2015 at 4:50 PM Jan-Ivar Bruaroey <jib at mozilla.com> wrote:

> Hi group! First post, so be gentle.
>

Welcome

>
> I love how arrow functions allow single arguments to be passed without
> parenthesis, so I expected this to work:
>
>      Promise.all([true, false]).then([foo, bar] => console.log(foo +”,
> "+ bar));
>
> but it doesn't:
>
>      SyntaxError: invalid arrow-function arguments (parentheses around
> the arrow-function may help)
>
> I understand from the spec that this is as defined, but is there a
> technical reason to disallow it?
>

To prevent ambiguity with:

MemberExpression Arguments
CallExpression Arguments


Arguments[Yield] :
( )
( ArgumentList[?Yield] )

ArgumentList[Yield] :
AssignmentExpression[In, ?Yield]
... AssignmentExpression[In, ?Yield]
ArgumentList[?Yield] , AssignmentExpression[In, ?Yield]
ArgumentList[?Yield] , ... AssignmentExpression[In, ?Yield]


e.g.

  fn([a, b])

Rick


> The parenthesis seem redundant to the naked eye.
>
> Thanks,
>
> .: Jan-Ivar :.
>
> _______________________________________________
> 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/20150320/4feeb7a2/attachment.html>


More information about the es-discuss mailing list