Lets say I have the following codes:
This example works
... .filter(([,second]) => console.log(second))This does not
... .filter([,second] => console.log(second))
Why do we have to wrap array destruction into parentheses? Isn't it boilerplate?
Lets say I have the following codes:
This example works
...
.filter(([,second]) => console.log(second))
This does not
...
.filter([,second] => console.log(second))
Why do we have to wrap array destruction into parentheses? Isn't it boilerplate?
This is just the what the ES2015 spec states the behavior should be. The () are only optional if the parameter list is just a single simple parameter.
From the spec
ArrowFunction[In, Yield] : ArrowParameters[?Yield] [no LineTerminator here] => ConciseBody[?In] ArrowParameters[Yield] : BindingIdentifier[?Yield] CoverParenthesizedExpressionAndArrowParameterList
So the arrow parameters can be either a binding identifier or a CoverParenthesizedExpressionAndArrowParameterList
The CoverParenthesizedExpressionAndArrowParameterList is a regular parameter list (as seen here)
CoverParenthesizedExpressionAndArrowParameterList[Yield] : ( Expression[In, ?Yield] ) ( ) ( ... BindingIdentifier[?Yield] ) ( Expression[In, ?Yield] , ... BindingIdentifier[?Yield] )
So the case when we can write a simple parameter is the BindingIdentifier case, which as seen here is just a simple identifier, so you can't use a de-structuring pattern:
BindingIdentifier[Yield] :Identifier