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/ ).
Spec:
https://tc39.github.io/proposal-trailing-function-commas/
Tracking bug:
https://bugs.chromium.org/p/v8/issues/detail?id=5051
Entry on the feature dashboard ( https://www.chromestatus.com/features
):
https://www.chromestatus.com/feature/5656834660630528
--
--
v8-users mailing list
[email protected]
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 [email protected].
For more options, visit https://groups.google.com/d/optout.