特别说明:转载与网络:https://github.com/adamlu/javascript-style-guide
-
不要将逗号放前面
// bad var once , upon , aTime; // good var once, upon, aTime; // bad var hero = { firstName: 'Bob' , lastName: 'Parr' , heroName: 'Mr. Incredible' , superPower: 'strength' }; // good var hero = { firstName: 'Bob', lastName: 'Parr', heroName: 'Mr. Incredible', superPower: 'strength' };
-
不要加多余的逗号,这可能会在IE下引起错误,同时如果多一个逗号某些ES3的实现会计算多数组的长度。
// bad var hero = { firstName: 'Kevin', lastName: 'Flynn', }; var heroes = [ 'Batman', 'Superman', ]; // good var hero = { firstName: 'Kevin', lastName: 'Flynn' }; var heroes = [ 'Batman', 'Superman' ];
本文详细介绍了 JavaScript 编程中的一些基本代码风格规范,重点强调了逗号的使用方式,包括逗号的位置以及避免在对象和数组定义时使用不必要的逗号。
198

被折叠的 条评论
为什么被折叠?



