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)
- [2.2](#references--disallow-var) If you must reassign references, use `let` instead of `var`. eslint: [`no-var`](http://eslint.org/docs/rules/no-var.html) jscs: [`disallowVar`](http://jscs.info/rule/disallowVar)
- [3.4](#es6-object-concise) Use property value shorthand. eslint: [`object-shorthand`](http://eslint.org/docs/rules/object-shorthand.html) jscs: [`requireEnhancedObjectLiterals`](http://jscs.info/rule/requireEnhancedObjectLiterals)
- [3.6](#objects--quoted-props) Only quote properties that are invalid identifiers. eslint: [`quote-props`](http://eslint.org/docs/rules/quote-props.html) jscs: [`disallowQuotedKeysInObjects`](http://jscs.info/rule/disallowQuotedKeysInObjects)
> Why?In general we consider it subjectively easier to read. It improves syntax highlighting, and is also more easily optimized by many JS engines.
258
+
> Why?总体来说更易读。对语法高亮更友好,并且更容易被JS引擎所优化。
259
259
260
260
```javascript
261
261
// bad
@@ -274,9 +274,9 @@ Other Style Guides
274
274
```
275
275
276
276
<a name="objects--prototype-builtins"></a>
277
-
- [3.7](#objects--prototype-builtins) Do not call `Object.prototype`methods directly, such as `hasOwnProperty`, `propertyIsEnumerable`, and`isPrototypeOf`.
> Why?These methods may be shadowed by properties on the object in question - consider `{ hasOwnProperty: false }`-or, the object may be a nullobject (`Object.create(null)`).
- [3.8](#objects--rest-spread) Prefer the object spread operator over [`Object.assign`](https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/Object/assign) to shallow-copy objects. Use the object rest operator to get a new object with certain properties omitted.
- [4.1](#arrays--literals) Use the literal syntax for array creation. eslint: [`no-array-constructor`](http://eslint.org/docs/rules/no-array-constructor.html)
- [4.2](#arrays--push) Use [Array#push](https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/Array/push) instead of direct assignment to add items to an array.
- [4.3](#es6-array-spreads) Use array spreads `...` to copy arrays.
345
+
- [4.3](#es6-array-spreads) 拷贝数组时用展开运算符 `...`.
346
346
347
347
```javascript
348
348
// bad
@@ -359,15 +359,15 @@ Other Style Guides
359
359
```
360
360
361
361
<a name="arrays--from"></a><a name="4.4"></a>
362
-
- [4.4](#arrays--from) To convert an array-like object to an array, use [Array.from](https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/Array/from).
- [4.5](#arrays--callback-return) Use return statements in array method callbacks. It's ok to omit the return if the function body consists of a single statement following [8.2](#8.2). eslint: [`array-callback-return`](http://eslint.org/docs/rules/array-callback-return)
- [5.1](#destructuring--object) Use object destructuring when accessing and using multiple properties of an object. jscs: [`requireObjectDestructuring`](http://jscs.info/rule/requireObjectDestructuring)
- [5.3](#destructuring--object-over-array) Use object destructuring for multiple return values, not array destructuring. jscs: [`disallowArrayDestructuringReturn`](http://jscs.info/rule/disallowArrayDestructuringReturn)
> Why? You can add new properties over time or change the order of things without breaking call sites.
504
+
> Why?你可以随时添加新的属性,或者更改顺序,而不会影响调用方。
505
505
506
506
```javascript
507
507
// bad
@@ -529,7 +529,7 @@ Other Style Guides
529
529
## Strings
530
530
531
531
<a name="strings--quotes"></a><a name="6.1"></a>
532
-
- [6.1](#strings--quotes) Use single quotes `''` for strings. eslint: [`quotes`](http://eslint.org/docs/rules/quotes.html) jscs: [`validateQuoteMarks`](http://jscs.info/rule/validateQuoteMarks)
- [6.2](#strings--line-length) Strings that cause the line to go over 100 characters should not be written across multiple lines using string concatenation.
- [6.3](#es6-template-literals) When programmatically building up strings, use template strings instead of concatenation. eslint: [`prefer-template`](http://eslint.org/docs/rules/prefer-template.html) [`template-curly-spacing`](http://eslint.org/docs/rules/template-curly-spacing) jscs: [`requireTemplateStrings`](http://jscs.info/rule/requireTemplateStrings)
- [6.5](#strings--escaping) Do not unnecessarily escape characters in strings. eslint: [`no-useless-escape`](http://eslint.org/docs/rules/no-useless-escape)
0 commit comments