JavaScript函数调用中的结尾逗号 [英] Trailing comma in JavaScript function call
问题描述
我正在尝试遵循 Airbnb 。
函数调用参数尾部逗号的规则为:
The rule on trailing commas for function call arguments states:
7.15带有多行签名或调用的函数应该像本指南中的其他多行列表一样缩进:每个项目本身一行,最后一个项目后面带有逗号。
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,
);
Chrome浏览器抱怨以下错误:
Google Chrome complains with the following error:
app.js:11 Uncaught SyntaxError:Unexpected token)
app.js:11 Uncaught SyntaxError: Unexpected token )
当我删除尾部逗号工作良好。该代码在Firefox中可以正常工作,我相当确定从今天(11.04.2017)开始也可以在Chrome中使用它-因为自那时以来我一直没有更改代码,而我正在展示我正在开发的应用程序我的同事。
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?
在Ubuntu 16.04上使用Google Chrome(版本57.0.2987.133(64位))。
Using Google Chrome (Version 57.0.2987.133 (64-bit)) on Ubuntu 16.04.
推荐答案
我的团队刚遇到一个拥有 Chrome 55.0.2883.87 的用户的问题。
此版本的Chrome还在上面的')'处报告了意外的令牌。
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.
Chrome 60.0似乎拖尾了逗号。 3112.113 。
没有错误。
The trailing commas DO seem to be TOLERATED by Chrome 60.0.3112.113. No error.
因此我们可以推断出Google正朝着支持试用逗号的方向发展。
So we can deduce that Google is moving towards support for the trialing comma.
这篇关于JavaScript函数调用中的结尾逗号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!