Intent to ship: Trailing comma in JavaScript function parameter lists

25 views
Skip to first unread message

jwolfe

unread,
Jan 13, 2017, 4:55:15 PM1/13/17
to v8-u...@googlegroups.com
Summary:

Allow a trailing comma in function parameter declarations and function call parameters. Example:

function f(a, b,) {
  return a + b;
}
let g = (a, b,) => a + b;
f(1, 2,) + g(3, 4,);

The purpose of this feature is to better support writing each parameter on its own line:

function f(
    longParameterName1, // documentation for parameter
    longParameterName2, // documentation for parameter
    longParameterName3, // documentation for parameter
  ) {
}
f(
  complicatedExpression(), // this is longParameterName1
  complicatedExpression(), // this is longParameterName2
  complicatedExpression(), // this is longParameterName3
);

Allowing the final comma is beneficial when editing the code. If you want to reorder the parameters, you needn't add and remove commas from some of the lines sometimes. If you want to add a new final parameter, you can simply add a line without modifying the previous line. This makes version-control diffs cleaner and also makes editing code less troublesome and error prone. Trailing commas are allowed in array and object literal syntax for the same reasons.


Interoperability and Compatibility Risk:

This new language feature allows syntax that was previously a SyntaxError, so compatibility risk is low.

This feature is in the draft ES2017 spec.

Firefox has implemented ( https://bugzilla.mozilla.org/show_bug.cgi?id=1303788 ) but not yet shipped this feature.
Webkit has implemented ( https://bugs.webkit.org/show_bug.cgi?id=158020 ) but not yet shipped this feature.
Edge is shipping with this feature enabled ( https://kangax.github.io/compat-table/es2016plus/ ).
 

Adam Klein

unread,
Jan 13, 2017, 5:05:20 PM1/13/17
to v8-users
LGTM

--
--
v8-users mailing list
v8-u...@googlegroups.com
http://groups.google.com/group/v8-users
---
You received this message because you are subscribed to the Google Groups "v8-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to v8-users+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Sathya Gunasekaran

unread,
Jan 13, 2017, 6:41:37 PM1/13/17
to v8-u...@googlegroups.com
LGTM

On Fri, Jan 13, 2017 at 1:55 PM, jwolfe <jwo...@igalia.com> wrote:
> --
> --
> v8-users mailing list
> v8-u...@googlegroups.com
> http://groups.google.com/group/v8-users
> ---
> You received this message because you are subscribed to the Google Groups
> "v8-users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to v8-users+u...@googlegroups.com.

PhistucK

unread,
Jan 13, 2017, 6:55:49 PM1/13/17
to jwolfe, v8-users

On Fri, Jan 13, 2017 at 11:55 PM, jwolfe <jwo...@igalia.com> wrote:
Edge is shipping with this feature enabled ( https://kangax.github.io/compat-table/es2016plus/ ).

​Actually, it is only shipping in preview builds of Windows 10 Creator's Update. EdgeHTML 15 is not the current stable build​. So the situation is the same as with WebKit and Gecko.

I really do not like this feature (why does C++ exclude this?)... JavaScript is loose enough as it is, but this is not the place for such feedback. :)



PhistucK

Benedikt Meurer

unread,
Jan 14, 2017, 7:24:21 AM1/14/17
to v8-u...@googlegroups.com, jwolfe

LGTM


--
Reply all
Reply to author
Forward
0 new messages