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
- [2.1](#references--prefer-const) Use `const` forallof your references; avoid using `var`. eslint: [`prefer-const`](http://eslint.org/docs/rules/prefer-const.html), [`no-const-assign`](http://eslint.org/docs/rules/no-const-assign.html)
99
99
100
-
> Why? This ensures that you can't reassign your references, which can lead to bugs and difficult to comprehend code.
100
+
> Why? This ensures that you can’t reassign your references, which can lead to bugs and difficult to comprehend code.
101
101
102
102
```javascript
103
103
// bad
@@ -708,7 +708,7 @@ Other Style Guides
708
708
```javascript
709
709
// really bad
710
710
functionhandleThings(opts) {
711
-
// No! We shouldn't mutate function arguments.
711
+
// No! We shouldn’t mutate function arguments.
712
712
// Double bad: if opts is falsy it'll be set to an object which may
713
713
// be what you want but it can introduce subtle bugs.
- [7.14](#functions--spread-vs-apply) Prefer the use of the spread operator `...` to call variadic functions. eslint: [`prefer-spread`](http://eslint.org/docs/rules/prefer-spread)
840
840
841
-
> Why? It’s cleaner, you don't need to supply a context, and you can not easily compose `new` with `apply`.
841
+
> Why? It’s cleaner, you don’t need to supply a context, and you can not easily compose `new`with`apply`.
842
842
843
843
```javascript
844
844
// bad
@@ -1354,7 +1354,7 @@ Other Style Guides
1354
1354
## Iterators and Generators
1355
1355
1356
1356
<a name="iterators--nope"></a><a name="11.1"></a>
1357
-
- [11.1](#iterators--nope) Don't use iterators. Prefer JavaScript’s higher-order functions instead of loops like `for-in` or `for-of`. eslint: [`no-iterator`](http://eslint.org/docs/rules/no-iterator.html) [`no-restricted-syntax`](http://eslint.org/docs/rules/no-restricted-syntax)
1357
+
- [11.1](#iterators--nope) Don’t use iterators. Prefer JavaScript’s higher-order functions instead of loops like `for-in` or `for-of`. eslint: [`no-iterator`](http://eslint.org/docs/rules/no-iterator.html) [`no-restricted-syntax`](http://eslint.org/docs/rules/no-restricted-syntax)
1358
1358
1359
1359
> Why? This enforces our immutable rule. Dealingwith pure functions that return values is easier to reason about than side effects.
- [11.2](#generators--nope) Don't use generators for now.
1401
+
- [11.2](#generators--nope) Don’t use generators for now.
1402
1402
1403
-
> Why? They don't transpile well to ES5.
1403
+
> Why? They don’t transpile well to ES5.
1404
1404
1405
1405
<a name="generators--spacing"></a>
1406
1406
- [11.3](#generators--spacing) If you must use generators, or if you disregard [our advice](#generators--nope), make sure their function signature is spaced properly. eslint: [`generator-star-spacing`](http://eslint.org/docs/rules/generator-star-spacing)
> Why? Chaining variable assignments creates implicit global variables.
1608
1608
@@ -1676,7 +1676,7 @@ Other Style Guides
1676
1676
- [14.1](#hoisting--about) `var` declarations get hoisted to the top of their scope, their assignment does not. `const` and `let` declarationsareblessedwithanewconceptcalled [TemporalDeadZones (TDZ)](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/let#Temporal_dead_zone_and_errors_with_let). It’s important to know why [typeof is no longer safe](http://es-discourse.com/t/why-typeof-is-no-longer-safe/15).
1677
1677
1678
1678
```javascript
1679
-
// we know this wouldn't work (assuming there
1679
+
// we know this wouldn’t work (assuming there
1680
1680
// is no notDefined global variable)
1681
1681
function example() {
1682
1682
console.log(notDefined); // => throws a ReferenceError
> 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](https://github.com/airbnb/javascript/blob/es5-deprecated/es5/README.md#commas) in legacy browsers.
2538
+
> 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](https://github.com/airbnb/javascript/blob/es5-deprecated/es5/README.md#commas) in legacy browsers.
- [23.4](#naming--leading-underscore) Do not use trailing or leading underscores. eslint: [`no-underscore-dangle`](http://eslint.org/docs/rules/no-underscore-dangle.html) jscs: [`disallowDanglingUnderscores`](http://jscs.info/rule/disallowDanglingUnderscores)
2806
2806
2807
-
> Why? JavaScript does not have the concept of privacy in terms of properties or methods. Although a leading underscore is a common convention to mean “private”, in fact, these properties are fully public, and as such, are part of your public API contract. This convention might lead developers to wrongly think that a change won't count as breaking, or that tests aren't needed. tl;dr: if you want something to be “private”, it must not be observably present.
2807
+
> Why? JavaScript does not have the concept of privacy in terms of properties or methods. Although a leading underscore is a common convention to mean “private”, in fact, these properties are fully public, and as such, are part of your public API contract. This convention might lead developers to wrongly think that a change won’t count as breaking, or that tests aren’t needed. tl;dr: if you want something to be “private”, it must not be observably present.
- [23.5](#naming--self-this) Don't save references to `this`. Use arrow functions or [Function#bind](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/bind). jscs: [`disallowNodeTypes`](http://jscs.info/rule/disallowNodeTypes)
2820
+
- [23.5](#naming--self-this) Don’t save references to `this`. Use arrow functions or [Function#bind](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/bind). jscs: [`disallowNodeTypes`](http://jscs.info/rule/disallowNodeTypes)
2821
2821
2822
2822
```javascript
2823
2823
// bad
@@ -3234,7 +3234,7 @@ Other Style Guides
3234
3234
- [Third Party JavaScript](https://www.manning.com/books/third-party-javascript) - Ben Vinegar and Anton Kovalyov
3235
3235
- [Effective JavaScript: 68 Specific Ways to Harness the Power of JavaScript](http://amzn.com/0321812182) - David Herman
0 commit comments