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:





  1. This example works



    ...
    .filter(([,second]) => console.log(second))



  2. This does not



    ...
    .filter([,second] => console.log(second))



Why do we have to wrap array destruction into parentheses? Isn't it boilerplate?










share|improve this question
























  • 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















up vote
4
down vote

favorite












Lets say I have the following codes:





  1. This example works



    ...
    .filter(([,second]) => console.log(second))



  2. This does not



    ...
    .filter([,second] => console.log(second))



Why do we have to wrap array destruction into parentheses? Isn't it boilerplate?










share|improve this question
























  • 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













up vote
4
down vote

favorite









up vote
4
down vote

favorite











Lets say I have the following codes:





  1. This example works



    ...
    .filter(([,second]) => console.log(second))



  2. This does not



    ...
    .filter([,second] => console.log(second))



Why do we have to wrap array destruction into parentheses? Isn't it boilerplate?










share|improve this question















Lets say I have the following codes:





  1. This example works



    ...
    .filter(([,second]) => console.log(second))



  2. This does not



    ...
    .filter([,second] => console.log(second))



Why do we have to wrap array destruction into parentheses? Isn't it boilerplate?







javascript typescript






share|improve this question















share|improve this question













share|improve this question




share|improve this question








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


















  • 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












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






share|improve this answer





















  • 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











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














 

draft saved


draft discarded


















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
































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






share|improve this answer





















  • 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















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






share|improve this answer





















  • 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













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






share|improve this answer












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







share|improve this answer












share|improve this answer



share|improve this answer










answered Nov 8 at 9:34









Titian Cernicova-Dragomir

50.8k33148




50.8k33148












  • 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












  • @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


















 

draft saved


draft discarded



















































 


draft saved


draft discarded














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




















































































Popular posts from this blog

How to pass form data using jquery Ajax to insert data in database?

National Museum of Racing and Hall of Fame

Guess what letter conforming each word