Skip to content

Commit fc248e6

Browse files
committed
Merge pull request airbnb#328 from airbnb/es6-trailing-commas
[commas] additional trailing commas good in es6. fixes airbnb#323
2 parents 120a122 + 7ade954 commit fc248e6

File tree

1 file changed

+21
-6
lines changed

1 file changed

+21
-6
lines changed

README.md

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1470,31 +1470,46 @@
14701470
};
14711471
```
14721472
1473-
- 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)):
1473+
- Additional trailing comma: **Yup.**
14741474
1475-
> 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.
1475+
> Why? This leads to cleaner git diffs. Also, transpilers like Babel will remove the additional trailing comma in the transpiled code which means you don't have to worry about the [trailing comma problem](es5/README.md#commas) in legacy browsers.
14761476
14771477
```javascript
1478+
// bad - git diff without trailing comma
1479+
const hero = {
1480+
firstName: 'Bob',
1481+
- lastName: 'Parr'
1482+
+ lastName: 'Parr',
1483+
+ heroName: 'Mr. Incredible'
1484+
}
1485+
1486+
// good - git diff with trailing comma
1487+
const hero = {
1488+
firstName: 'Bob',
1489+
lastName: 'Parr',
1490+
+ heroName: 'Mr. Incredible',
1491+
}
1492+
14781493
// bad
14791494
const hero = {
14801495
firstName: 'Kevin',
1481-
lastName: 'Flynn',
1496+
lastName: 'Flynn'
14821497
};
14831498

14841499
const heroes = [
14851500
'Batman',
1486-
'Superman',
1501+
'Superman'
14871502
];
14881503

14891504
// good
14901505
const hero = {
14911506
firstName: 'Kevin',
1492-
lastName: 'Flynn'
1507+
lastName: 'Flynn',
14931508
};
14941509

14951510
const heroes = [
14961511
'Batman',
1497-
'Superman'
1512+
'Superman',
14981513
];
14991514
```
15001515

0 commit comments

Comments
 (0)