mirror of
https://github.com/airbnb/javascript.git
synced 2026-01-14 03:48:00 -05:00
[guide] change more straight quotes to curly quotes
This commit is contained in:
28
README.md
28
README.md
@@ -97,7 +97,7 @@ Other Style Guides
|
||||
<a name="references--prefer-const"></a><a name="2.1"></a>
|
||||
- [2.1](#references--prefer-const) Use `const` for all of 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)
|
||||
|
||||
> Why? This ensures that you can't reassign your references, which can lead to bugs and difficult to comprehend code.
|
||||
> Why? This ensures that you can’t reassign your references, which can lead to bugs and difficult to comprehend code.
|
||||
|
||||
```javascript
|
||||
// bad
|
||||
@@ -708,7 +708,7 @@ Other Style Guides
|
||||
```javascript
|
||||
// really bad
|
||||
function handleThings(opts) {
|
||||
// No! We shouldn't mutate function arguments.
|
||||
// No! We shouldn’t mutate function arguments.
|
||||
// Double bad: if opts is falsy it'll be set to an object which may
|
||||
// be what you want but it can introduce subtle bugs.
|
||||
opts = opts || {};
|
||||
@@ -838,7 +838,7 @@ Other Style Guides
|
||||
<a name="functions--spread-vs-apply"></a><a name="7.14"></a>
|
||||
- [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)
|
||||
|
||||
> Why? It’s cleaner, you don't need to supply a context, and you can not easily compose `new` with `apply`.
|
||||
> Why? It’s cleaner, you don’t need to supply a context, and you can not easily compose `new` with `apply`.
|
||||
|
||||
```javascript
|
||||
// bad
|
||||
@@ -1354,7 +1354,7 @@ Other Style Guides
|
||||
## Iterators and Generators
|
||||
|
||||
<a name="iterators--nope"></a><a name="11.1"></a>
|
||||
- [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)
|
||||
- [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)
|
||||
|
||||
> Why? This enforces our immutable rule. Dealing with pure functions that return values is easier to reason about than side effects.
|
||||
|
||||
@@ -1398,9 +1398,9 @@ Other Style Guides
|
||||
```
|
||||
|
||||
<a name="generators--nope"></a><a name="11.2"></a>
|
||||
- [11.2](#generators--nope) Don't use generators for now.
|
||||
- [11.2](#generators--nope) Don’t use generators for now.
|
||||
|
||||
> Why? They don't transpile well to ES5.
|
||||
> Why? They don’t transpile well to ES5.
|
||||
|
||||
<a name="generators--spacing"></a>
|
||||
- [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)
|
||||
@@ -1602,7 +1602,7 @@ Other Style Guides
|
||||
}
|
||||
```
|
||||
<a name="variables--no-chain-assignment"></a><a name="13.5"></a>
|
||||
- [13.5](#variables--no-chain-assignment) Don't chain variable assignments.
|
||||
- [13.5](#variables--no-chain-assignment) Don’t chain variable assignments.
|
||||
|
||||
> Why? Chaining variable assignments creates implicit global variables.
|
||||
|
||||
@@ -1676,7 +1676,7 @@ Other Style Guides
|
||||
- [14.1](#hoisting--about) `var` declarations get hoisted to the top of their scope, their assignment does not. `const` and `let` declarations are blessed with a new concept called [Temporal Dead Zones (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).
|
||||
|
||||
```javascript
|
||||
// we know this wouldn't work (assuming there
|
||||
// we know this wouldn’t work (assuming there
|
||||
// is no notDefined global variable)
|
||||
function example() {
|
||||
console.log(notDefined); // => throws a ReferenceError
|
||||
@@ -2147,7 +2147,7 @@ Other Style Guides
|
||||
constructor() {
|
||||
super();
|
||||
|
||||
// FIXME: shouldn't use a global here
|
||||
// FIXME: shouldn’t use a global here
|
||||
total = 0;
|
||||
}
|
||||
}
|
||||
@@ -2535,7 +2535,7 @@ Other Style Guides
|
||||
<a name="commas--dangling"></a><a name="19.2"></a>
|
||||
- [20.2](#commas--dangling) Additional trailing comma: **Yup.** eslint: [`comma-dangle`](http://eslint.org/docs/rules/comma-dangle.html) jscs: [`requireTrailingComma`](http://jscs.info/rule/requireTrailingComma)
|
||||
|
||||
> 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.
|
||||
> 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.
|
||||
|
||||
```diff
|
||||
// bad - git diff without trailing comma
|
||||
@@ -2674,7 +2674,7 @@ Other Style Guides
|
||||
const totalScore = this.reviewScore + ''; // invokes this.reviewScore.valueOf()
|
||||
|
||||
// bad
|
||||
const totalScore = this.reviewScore.toString(); // isn't guaranteed to return a string
|
||||
const totalScore = this.reviewScore.toString(); // isn’t guaranteed to return a string
|
||||
|
||||
// good
|
||||
const totalScore = String(this.reviewScore);
|
||||
@@ -2804,7 +2804,7 @@ Other Style Guides
|
||||
<a name="naming--leading-underscore"></a><a name="22.4"></a>
|
||||
- [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)
|
||||
|
||||
> 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.
|
||||
> 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.
|
||||
|
||||
```javascript
|
||||
// bad
|
||||
@@ -2817,7 +2817,7 @@ Other Style Guides
|
||||
```
|
||||
|
||||
<a name="naming--self-this"></a><a name="22.5"></a>
|
||||
- [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)
|
||||
- [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)
|
||||
|
||||
```javascript
|
||||
// bad
|
||||
@@ -3234,7 +3234,7 @@ Other Style Guides
|
||||
- [Third Party JavaScript](https://www.manning.com/books/third-party-javascript) - Ben Vinegar and Anton Kovalyov
|
||||
- [Effective JavaScript: 68 Specific Ways to Harness the Power of JavaScript](http://amzn.com/0321812182) - David Herman
|
||||
- [Eloquent JavaScript](http://eloquentjavascript.net/) - Marijn Haverbeke
|
||||
- [You Don't Know JS: ES6 & Beyond](http://shop.oreilly.com/product/0636920033769.do) - Kyle Simpson
|
||||
- [You Don’t Know JS: ES6 & Beyond](http://shop.oreilly.com/product/0636920033769.do) - Kyle Simpson
|
||||
|
||||
**Blogs**
|
||||
|
||||
|
||||
Reference in New Issue
Block a user