You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+69-21Lines changed: 69 additions & 21 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -94,7 +94,7 @@ Other Style Guides (from Airbnb)
94
94
95
95
- [2.1](#2.1) <a name='2.1'></a> Use `const`for all of your references; avoid using `var`.
96
96
97
-
> Why? This ensures that you can't reassign your references (mutation), which can lead to bugs and difficult to comprehend code.
97
+
> Why? This ensures that you can't reassign your references, which can lead to bugs and difficult to comprehend code.
98
98
99
99
```javascript
100
100
// bad
@@ -106,7 +106,7 @@ Other Style Guides (from Airbnb)
106
106
const b = 2;
107
107
```
108
108
109
-
- [2.2](#2.2) <a name='2.2'></a> If you must mutate references, use `let` instead of `var`.
109
+
- [2.2](#2.2) <a name='2.2'></a> If you must reassign references, use `let` instead of `var`.
110
110
111
111
> Why? `let` is block-scoped rather than function-scoped like `var`.
112
112
@@ -452,7 +452,7 @@ Other Style Guides (from Airbnb)
452
452
return `How are you, ${name}?`;
453
453
}
454
454
```
455
-
- [6.5](#6.5) <a name='6.5'></a> Never use eval() on a string, it opens too many vulnerabilities.
455
+
- [6.5](#6.5) <a name='6.5'></a> Never use `eval()` on a string, it opens too many vulnerabilities.
456
456
457
457
**[⬆ back to top](#table-of-contents)**
458
458
@@ -1114,7 +1114,7 @@ Other Style Guides (from Airbnb)
1114
1114
}
1115
1115
```
1116
1116
1117
-
- For more information refer to [JavaScript Scoping & Hoisting](http://www.adequatelygood.com/2010/2/JavaScript-Scoping-and-Hoisting) by [Ben Cherry](http://www.adequatelygood.com/).
1117
+
- For more information refer to [JavaScript Scoping & Hoisting](http://www.adequatelygood.com/2010/2/JavaScript-Scoping-and-Hoisting/) by [Ben Cherry](http://www.adequatelygood.com/).
1118
1118
1119
1119
**[⬆ back to top](#table-of-contents)**
1120
1120
@@ -1253,7 +1253,7 @@ Other Style Guides (from Airbnb)
1253
1253
}
1254
1254
```
1255
1255
1256
-
- [17.2](#17.2) <a name='17.2'></a> Use `//` for single line comments. Place single line comments on a newline above the subject of the comment. Put an empty line before the comment.
1256
+
- [17.2](#17.2) <a name='17.2'></a> Use `//` for single line comments. Place single line comments on a newline above the subject of the comment. Put an empty line before the comment unless it's on the first line of a block.
1257
1257
1258
1258
```javascript
1259
1259
// bad
@@ -1281,6 +1281,14 @@ Other Style Guides (from Airbnb)
1281
1281
1282
1282
return type;
1283
1283
}
1284
+
1285
+
// also good
1286
+
function getType() {
1287
+
// set the default type to 'no type'
1288
+
const type = this._type || 'no type';
1289
+
1290
+
return type;
1291
+
}
1284
1292
```
1285
1293
1286
1294
- [17.3](#17.3) <a name='17.3'></a> Prefixing your comments with`FIXME` or `TODO` helps other developers quickly understand if you're pointing out a problem that needs to be revisited, or if you're suggesting a solution to the problem that needs to be implemented. These are different than regular comments because they are actionable. The actions are `FIXME -- need to figure this out` or `TODO -- need to implement`.
@@ -1516,6 +1524,38 @@ Other Style Guides (from Airbnb)
1516
1524
return arr;
1517
1525
```
1518
1526
1527
+
- [18.8](#18.8) <a name='18.8'></a> Do not pad your blocks with blank lines.
1528
+
1529
+
```javascript
1530
+
// bad
1531
+
functionbar() {
1532
+
1533
+
console.log(foo);
1534
+
1535
+
}
1536
+
1537
+
// also bad
1538
+
if (baz) {
1539
+
1540
+
console.log(qux);
1541
+
} else {
1542
+
console.log(foo);
1543
+
1544
+
}
1545
+
1546
+
// good
1547
+
functionbar() {
1548
+
console.log(foo);
1549
+
}
1550
+
1551
+
// good
1552
+
if (baz) {
1553
+
console.log(qux);
1554
+
} else {
1555
+
console.log(foo);
1556
+
}
1557
+
```
1558
+
1519
1559
1520
1560
**[⬆ back to top](#table-of-contents)**
1521
1561
@@ -1625,7 +1665,7 @@ Other Style Guides (from Airbnb)
@@ -1994,7 +2034,7 @@ Other Style Guides (from Airbnb)
1994
2034
1995
2035
## ECMAScript 5 Compatibility
1996
2036
1997
-
- [26.1](#26.1) <a name='26.1'></a> Refer to [Kangax](https://twitter.com/kangax/)'s ES5 [compatibility table](http://kangax.github.com/es5-compat-table/).
2037
+
- [26.1](#26.1) <a name='26.1'></a> Refer to [Kangax](https://twitter.com/kangax/)'s ES5 [compatibility table](http://kangax.github.io/es5-compat-table/).
1998
2038
1999
2039
**[⬆ back to top](#table-of-contents)**
2000
2040
@@ -2028,6 +2068,14 @@ Other Style Guides (from Airbnb)
2028
2068
}
2029
2069
```
2030
2070
2071
+
- [28.2](#28.2) <a name="28.2"></a> **No, but seriously**:
2072
+
- Whichever testing framework you use, you should be writing tests!
2073
+
- Strive to write many small pure functions, and minimize where mutations occur.
2074
+
- Be cautious about stubs and mocks - they can make your tests more brittle.
2075
+
- We primarily use [`mocha`](https://www.npmjs.com/package/mocha) at Airbnb. [`tape`](https://www.npmjs.com/package/tape) is also used occasionally for small, separate modules.
2076
+
- 100% test coverage is a good goal to strive for, even if it's not always practical to reach it.
2077
+
- Whenever you fix a bug, _write a regression test_. A bug fixed without a regression test is almost certainly going to break again in the future.
2078
+
2031
2079
**[⬆ back to top](#table-of-contents)**
2032
2080
2033
2081
@@ -2098,7 +2146,7 @@ Other Style Guides (from Airbnb)
2098
2146
2099
2147
## Performance
2100
2148
2101
-
- [On Layout & Web Performance](http://kellegous.com/j/2013/01/26/layout-performance/)
2149
+
- [On Layout & Web Performance](http://www.kellegous.com/j/2013/01/26/layout-performance/)
2102
2150
- [String vs Array Concat](http://jsperf.com/string-vs-array-concat/2)
2103
2151
- [Try/Catch Cost In a Loop](http://jsperf.com/try-catch-in-loop-cost)
0 commit comments