Reformat var change

This commit is contained in:
Jake Teton-Landis
2014-12-03 17:41:15 -08:00
parent b61d52ca41
commit 3c68fc4946

View File

@@ -367,6 +367,9 @@
```
- Use one `var` declaration per variable.
It's easier to add new variable declarations this way, and you never have
to worry about swapping out a `;` for a `,` or introducing punctuation-only
diffs.
```javascript
// bad
@@ -374,23 +377,18 @@
goSportsTeam = true,
dragonball = 'z';
// bad
// (compare to above, and try to spot the mistake)
var items = getItems(),
goSportsTeam = true;
dragonball = 'z';
// good
var items = getItems();
var goSportsTeam = true;
var dragonball = 'z';
```
It's easier to add new variable declarations this way, and you never have
to worry about swapping out a `;` for a `,` or introducing punctuation-only
diffs. Also, you can't make the following mistake:
```javascript
// can you catch the error?
var items = getItems(),
goSportsTeam = true;
dragonball = 'z';
```
- Declare unassigned variables last. This is helpful when later on you might need to assign a variable depending on one of the previous assigned variables.
```javascript