Trailing comma in JavaScript function call

你。 提交于 2019-12-02 04:03:41

问题


I'm trying to follow the JS code style defined by Airbnb.

The rule on trailing commas for function call arguments states:

7.15 Functions with multiline signatures, or invocations, should be indented just like every other multiline list in this guide: with each item on a line by itself, with a trailing comma on the last item.

But when I do the following:

/* THREE.js constructor for PerspectiveCamera */
const camera = new THREE.PerspectiveCamera(
    75,
    window.innerWidth / window.innerHeight,
    0.1,
    1000,
);

Google Chrome complains with the following error:

app.js:11 Uncaught SyntaxError: Unexpected token )

When I remove the trailing comma everything works fine. This code works fine in Firefox and I am fairly sure it worked a week ago from today (11.04.2017) in Chrome as well - because I haven't changed my code since than and I was presenting the app I'm working on to my colleague.

Note that trailing comma in arrays still works fine:

testArray = [
    'one',
    'two',
    'three',
];

Can someone explain this behavior or point me to where I can look for more information?

Using Google Chrome (Version 57.0.2987.133 (64-bit)) on Ubuntu 16.04.


回答1:


My team just ran into this issue with a user who has Chrome 55.0.2883.87. This version of Chrome also reports unexpected token at ')' as reported above.

The trailing commas DO seem to be TOLERATED by Chrome 60.0.3112.113. No error.

So we can deduce that Google is moving towards support for the trialing comma.



来源:https://stackoverflow.com/questions/43339356/trailing-comma-in-javascript-function-call

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!