[commas] add section on additional trailing commas. fixes #75

This commit is contained in:
Harrison Shoff
2013-07-11 12:06:25 -07:00
parent e3e3cc1a4e
commit bf87eec199

View File

@@ -17,7 +17,7 @@
1. [Blocks](#blocks)
1. [Comments](#comments)
1. [Whitespace](#whitespace)
1. [Leading Commas](#leading-commas)
1. [Commas](#commas)
1. [Semicolons](#semicolons)
1. [Type Casting & Coercion](#type-coercion)
1. [Naming Conventions](#naming-conventions)
@@ -802,9 +802,9 @@
**[[⬆]](#TOC)**
## <a name='leading-commas'>Leading Commas</a>
## <a name='commas'>Commas</a>
- **Nope.**
- Leading commas: **Nope.**
```javascript
// bad
@@ -834,6 +834,34 @@
};
```
- Additional trailing comma: **Nope.** This can cause problems with IE6/7 and IE9 if it's in quirksmode. Also, in some implementations of ES3 would add length to an array if it had an additional trailing comma. This was clarified in ES5 ([source](http://es5.github.io/#D)):
> Edition 5 clarifies the fact that a trailing comma at the end of an ArrayInitialiser does not add to the length of the array. This is not a semantic change from Edition 3 but some implementations may have previously misinterpreted this.
```javascript
// bad
var hero = {
firstName: 'Kevin',
lastName: 'Flynn',
};
var heroes = [
'Batman',
'Superman',
];
// good
var hero = {
firstName: 'Kevin',
lastName: 'Flynn'
};
var heroes = [
'Batman',
'Superman'
];
```
**[[⬆]](#TOC)**