mirror of
https://github.com/airbnb/javascript.git
synced 2026-01-13 18:18:01 -05:00
[commas] add section on additional trailing commas. fixes #75
This commit is contained in:
34
README.md
34
README.md
@@ -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)**
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user