Why can't we omit parentheses from array destruction in array function parameters?
up vote
4
down vote
favorite
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?
javascript typescript
add a comment |
up vote
4
down vote
favorite
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?
javascript typescript
Arrow functions are defined like this in ES6 and later specs, so it's not necessarily a typescript-related issue. I agree though, I don't see a good reason for why there needs to be parentheses around arrays
– ShamPooSham
Nov 8 at 9:36
add a comment |
up vote
4
down vote
favorite
up vote
4
down vote
favorite
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?
javascript typescript
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?
javascript typescript
javascript typescript
edited Nov 8 at 9:40
asked Nov 8 at 9:12
Balázs Takács
588115
588115
Arrow functions are defined like this in ES6 and later specs, so it's not necessarily a typescript-related issue. I agree though, I don't see a good reason for why there needs to be parentheses around arrays
– ShamPooSham
Nov 8 at 9:36
add a comment |
Arrow functions are defined like this in ES6 and later specs, so it's not necessarily a typescript-related issue. I agree though, I don't see a good reason for why there needs to be parentheses around arrays
– ShamPooSham
Nov 8 at 9:36
Arrow functions are defined like this in ES6 and later specs, so it's not necessarily a typescript-related issue. I agree though, I don't see a good reason for why there needs to be parentheses around arrays
– ShamPooSham
Nov 8 at 9:36
Arrow functions are defined like this in ES6 and later specs, so it's not necessarily a typescript-related issue. I agree though, I don't see a good reason for why there needs to be parentheses around arrays
– ShamPooSham
Nov 8 at 9:36
add a comment |
1 Answer
1
active
oldest
votes
up vote
3
down vote
accepted
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
Thank you for the answer. Do you think it is something which worth modification request in the upcoming spec?
– Balázs Takács
Nov 8 at 9:38
@BalázsTakács don't know
– Titian Cernicova-Dragomir
Nov 8 at 9:39
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
3
down vote
accepted
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
Thank you for the answer. Do you think it is something which worth modification request in the upcoming spec?
– Balázs Takács
Nov 8 at 9:38
@BalázsTakács don't know
– Titian Cernicova-Dragomir
Nov 8 at 9:39
add a comment |
up vote
3
down vote
accepted
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
Thank you for the answer. Do you think it is something which worth modification request in the upcoming spec?
– Balázs Takács
Nov 8 at 9:38
@BalázsTakács don't know
– Titian Cernicova-Dragomir
Nov 8 at 9:39
add a comment |
up vote
3
down vote
accepted
up vote
3
down vote
accepted
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
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
answered Nov 8 at 9:34
Titian Cernicova-Dragomir
50.5k33148
50.5k33148
Thank you for the answer. Do you think it is something which worth modification request in the upcoming spec?
– Balázs Takács
Nov 8 at 9:38
@BalázsTakács don't know
– Titian Cernicova-Dragomir
Nov 8 at 9:39
add a comment |
Thank you for the answer. Do you think it is something which worth modification request in the upcoming spec?
– Balázs Takács
Nov 8 at 9:38
@BalázsTakács don't know
– Titian Cernicova-Dragomir
Nov 8 at 9:39
Thank you for the answer. Do you think it is something which worth modification request in the upcoming spec?
– Balázs Takács
Nov 8 at 9:38
Thank you for the answer. Do you think it is something which worth modification request in the upcoming spec?
– Balázs Takács
Nov 8 at 9:38
@BalázsTakács don't know
– Titian Cernicova-Dragomir
Nov 8 at 9:39
@BalázsTakács don't know
– Titian Cernicova-Dragomir
Nov 8 at 9:39
add a comment |
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53204573%2fwhy-cant-we-omit-parentheses-from-array-destruction-in-array-function-parameter%23new-answer', 'question_page');
}
);
Post as a guest
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Arrow functions are defined like this in ES6 and later specs, so it's not necessarily a typescript-related issue. I agree though, I don't see a good reason for why there needs to be parentheses around arrays
– ShamPooSham
Nov 8 at 9:36