From a2034b0f6ce448c272bd4c13773dfd710dbfeb89 Mon Sep 17 00:00:00 2001 From: Harrison Shoff Date: Wed, 29 Apr 2015 10:39:01 -0700 Subject: [PATCH 1/2] [commas] additional trailing commas good in es6. fixes #323 --- README.md | 36 +++++++++++++++++++++++++----------- 1 file changed, 25 insertions(+), 11 deletions(-) diff --git a/README.md b/README.md index 825ccfc5..ea5de7c7 100644 --- a/README.md +++ b/README.md @@ -1470,23 +1470,26 @@ }; ``` - - 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)): + - Additional trailing comma: **Yup.** - > 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. + > 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. ```javascript - // bad + // bad - git diff without trailing comma const hero = { - firstName: 'Kevin', - lastName: 'Flynn', - }; + - firstName: 'Bob', + + lastName: 'Parr', + + heroName: 'Mr. Incredible' + } - const heroes = [ - 'Batman', - 'Superman', - ]; + // good - git diff with trailing comma + const hero = { + firstName: 'Bob', + lastName: 'Parr', + + heroName: 'Mr. Incredible', + } - // good + // bad const hero = { firstName: 'Kevin', lastName: 'Flynn' @@ -1496,6 +1499,17 @@ 'Batman', 'Superman' ]; + + // good + const hero = { + firstName: 'Kevin', + lastName: 'Flynn', + }; + + const heroes = [ + 'Batman', + 'Superman', + ]; ``` **[⬆ back to top](#table-of-contents)** From 7ade95434c6d9e8faf862e6f69df1110449e4955 Mon Sep 17 00:00:00 2001 From: Harrison Shoff Date: Wed, 29 Apr 2015 10:42:03 -0700 Subject: [PATCH 2/2] [commas] fix bad git diff example --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index ea5de7c7..4ae97936 100644 --- a/README.md +++ b/README.md @@ -1477,7 +1477,8 @@ ```javascript // bad - git diff without trailing comma const hero = { - - firstName: 'Bob', + firstName: 'Bob', + - lastName: 'Parr' + lastName: 'Parr', + heroName: 'Mr. Incredible' }