Skip to content

Commit ee4ce9e

Browse files
author
zhangchunxiao
committed
translate part of
1 parent 5797f54 commit ee4ce9e

File tree

1 file changed

+41
-41
lines changed

1 file changed

+41
-41
lines changed

README.md

Lines changed: 41 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ Other Style Guides
5555
## Types
5656

5757
<a name="types--primitives"></a><a name="1.1"></a>
58-
- [1.1](#types--primitives) **Primitives**: When you access a primitive type you work directly on its value.
58+
- [1.1](#types--primitives) **基本类型**: 操作基本类型时操作的是它的值.
5959

6060
+ `string`
6161
+ `number`
@@ -73,7 +73,7 @@ Other Style Guides
7373
```
7474

7575
<a name="types--complex"></a><a name="1.2"></a>
76-
- [1.2](#types--complex) **Complex**: When you access a complex type you work on a reference to its value.
76+
- [1.2](#types--complex) **复杂类型**: 操作复杂类型时操作的是它的引用.
7777

7878
+ `object`
7979
+ `array`
@@ -90,12 +90,12 @@ Other Style Guides
9090

9191
**[⬆ back to top](#table-of-contents)**
9292

93-
## References
93+
## 引用
9494

9595
<a name="references--prefer-const"></a><a name="2.1"></a>
96-
- [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)
96+
- [2.1](#references--prefer-const) 定义变量时用 `const` ; 避免使用`var`. eslint: [`prefer-const`](http://eslint.org/docs/rules/prefer-const.html), [`no-const-assign`](http://eslint.org/docs/rules/no-const-assign.html)
9797

98-
> Why? This ensures that you can't reassign your references, which can lead to bugs and difficult to comprehend code.
98+
> Why? 这样可以确定变量不会被无意中重新赋值,从而避免bug.
9999

100100
```javascript
101101
// bad
@@ -108,9 +108,9 @@ Other Style Guides
108108
```
109109

110110
<a name="references--disallow-var"></a><a name="2.2"></a>
111-
- [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)
111+
- [2.2](#references--disallow-var) 如果必须对变量重新赋值, 用 `let` 而不是 `var`. eslint: [`no-var`](http://eslint.org/docs/rules/no-var.html) jscs: [`disallowVar`](http://jscs.info/rule/disallowVar)
112112

113-
> Why? `let` is block-scoped rather than function-scoped like `var`.
113+
> Why? `let` 是块级作用域,`var` 是函数级作用哉.
114114

115115
```javascript
116116
// bad
@@ -127,10 +127,10 @@ Other Style Guides
127127
```
128128

129129
<a name="references--block-scope"></a><a name="2.3"></a>
130-
- [2.3](#references--block-scope) Note that both `let` and `const` are block-scoped.
130+
- [2.3](#references--block-scope) 注意 `let` `const` 都是块级作用域.
131131

132132
```javascript
133-
// const and let only exist in the blocks they are defined in.
133+
// const let 只存在于它们定义的代码块中.
134134
{
135135
let a = 1;
136136
const b = 1;
@@ -144,7 +144,7 @@ Other Style Guides
144144
## Objects
145145

146146
<a name="objects--no-new"></a><a name="3.1"></a>
147-
- [3.1](#objects--no-new) Use the literal syntax for object creation. eslint: [`no-new-object`](http://eslint.org/docs/rules/no-new-object.html)
147+
- [3.1](#objects--no-new) 用对象字面量来给对象赋值. eslint: [`no-new-object`](http://eslint.org/docs/rules/no-new-object.html)
148148

149149
```javascript
150150
// bad
@@ -155,9 +155,9 @@ Other Style Guides
155155
```
156156

157157
<a name="es6-computed-properties"></a><a name="3.4"></a>
158-
- [3.2](#es6-computed-properties) Use computed property names when creating objects with dynamic property names.
158+
- [3.2](#es6-computed-properties) 当新对象属性是动态的时,使用需要计算的动态属性名称(computed property names).
159159

160-
> Why? They allow you to define all the properties of an object in one place.
160+
> Why? 这样你可以把属性定义在一块.
161161

162162
```javascript
163163
@@ -181,7 +181,7 @@ Other Style Guides
181181
```
182182

183183
<a name="es6-object-shorthand"></a><a name="3.5"></a>
184-
- [3.3](#es6-object-shorthand) Use object method shorthand. eslint: [`object-shorthand`](http://eslint.org/docs/rules/object-shorthand.html) jscs: [`requireEnhancedObjectLiterals`](http://jscs.info/rule/requireEnhancedObjectLiterals)
184+
- [3.3](#es6-object-shorthand) 使用对象方法简写形式. eslint: [`object-shorthand`](http://eslint.org/docs/rules/object-shorthand.html) jscs: [`requireEnhancedObjectLiterals`](http://jscs.info/rule/requireEnhancedObjectLiterals)
185185

186186
```javascript
187187
// bad
@@ -204,9 +204,9 @@ Other Style Guides
204204
```
205205

206206
<a name="es6-object-concise"></a><a name="3.6"></a>
207-
- [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)
207+
- [3.4](#es6-object-concise) 使用属性简写形式. eslint: [`object-shorthand`](http://eslint.org/docs/rules/object-shorthand.html) jscs: [`requireEnhancedObjectLiterals`](http://jscs.info/rule/requireEnhancedObjectLiterals)
208208

209-
> Why? It is shorter to write and descriptive.
209+
> Why? 代码更短.
210210

211211
```javascript
212212
const lukeSkywalker = 'Luke Skywalker';
@@ -223,9 +223,9 @@ Other Style Guides
223223
```
224224

225225
<a name="objects--grouped-shorthand"></a><a name="3.7"></a>
226-
- [3.5](#objects--grouped-shorthand) Group your shorthand properties at the beginning of your object declaration.
226+
- [3.5](#objects--grouped-shorthand) 把简写属性放在属性开始的位置.
227227

228-
> Why? It's easier to tell which properties are using the shorthand.
228+
> Why? 更容易看出哪些属性是简写的.
229229

230230
```javascript
231231
const anakinSkywalker = 'Anakin Skywalker';
@@ -253,9 +253,9 @@ Other Style Guides
253253
```
254254

255255
<a name="objects--quoted-props"></a><a name="3.8"></a>
256-
- [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)
256+
- [3.6](#objects--quoted-props) 只对不符合要求的属性名加引号. eslint: [`quote-props`](http://eslint.org/docs/rules/quote-props.html) jscs: [`disallowQuotedKeysInObjects`](http://jscs.info/rule/disallowQuotedKeysInObjects)
257257

258-
> 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引擎所优化。
259259

260260
```javascript
261261
// bad
@@ -274,9 +274,9 @@ Other Style Guides
274274
```
275275

276276
<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`.
277+
- [3.7](#objects--prototype-builtins) 不要直接调用 `Object.prototype` 方法, 比如 `hasOwnProperty`, `propertyIsEnumerable`, `isPrototypeOf`.
278278

279-
> Why? These methods may be shadowed by properties on the object in question - consider `{ hasOwnProperty: false }` - or, the object may be a null object (`Object.create(null)`).
279+
> Why? 这些方法有可能被自定义的属性覆盖,像这样 `{ hasOwnProperty: false }` - 或者,对象本身可能是一个空对象 (`Object.create(null)`).
280280

281281
```javascript
282282
// bad
@@ -294,7 +294,7 @@ Other Style Guides
294294
```
295295

296296
<a name="objects--rest-spread"></a>
297-
- [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.
297+
- [3.8](#objects--rest-spread) 在做对象拷贝时(shallow-copy)更推荐使用展开运算符,而不是 [`Object.assign`](https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/Object/assign) . 当需要忽略某些属性时使用rest操作符.
298298

299299
```javascript
300300
// very bad
@@ -318,7 +318,7 @@ Other Style Guides
318318
## Arrays
319319

320320
<a name="arrays--literals"></a><a name="4.1"></a>
321-
- [4.1](#arrays--literals) Use the literal syntax for array creation. eslint: [`no-array-constructor`](http://eslint.org/docs/rules/no-array-constructor.html)
321+
- [4.1](#arrays--literals) 用字面量语法创建数组. eslint: [`no-array-constructor`](http://eslint.org/docs/rules/no-array-constructor.html)
322322

323323
```javascript
324324
// bad
@@ -329,7 +329,7 @@ Other Style Guides
329329
```
330330

331331
<a name="arrays--push"></a><a name="4.2"></a>
332-
- [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.
332+
- [4.2](#arrays--push) [Array#push](https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/Array/push) 方法而不是直接定义数组元素.
333333

334334
```javascript
335335
const someStack = [];
@@ -342,7 +342,7 @@ Other Style Guides
342342
```
343343

344344
<a name="es6-array-spreads"></a><a name="4.3"></a>
345-
- [4.3](#es6-array-spreads) Use array spreads `...` to copy arrays.
345+
- [4.3](#es6-array-spreads) 拷贝数组时用展开运算符 `...`.
346346

347347
```javascript
348348
// bad
@@ -359,15 +359,15 @@ Other Style Guides
359359
```
360360

361361
<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).
362+
- [4.4](#arrays--from) 把一个 array-like 对象转化为数组时,用 [Array.from](https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/Array/from).
363363

364364
```javascript
365365
const foo = document.querySelectorAll('.foo');
366366
const nodes = Array.from(foo);
367367
```
368368

369369
<a name="arrays--callback-return"></a><a name="4.5"></a>
370-
- [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)
370+
- [4.5](#arrays--callback-return) 调用数组回调方法时使用return。当函数只有一行时,省略return是可以的,参见 [8.2](#8.2). eslint: [`array-callback-return`](http://eslint.org/docs/rules/array-callback-return)
371371

372372
```javascript
373373
// good
@@ -418,7 +418,7 @@ Other Style Guides
418418
**[⬆ back to top](#table-of-contents)**
419419

420420
<a name="arrays--bracket-newline"></a>
421-
- [4.6](#arrays--bracket-newline) Use line breaks after open and before close array brackets if an array has multiple lines
421+
- [4.6](#arrays--bracket-newline) 如果数组包含多行,在{后}前使用换行
422422

423423
```javascript
424424
// bad
@@ -459,9 +459,9 @@ Other Style Guides
459459
## Destructuring
460460

461461
<a name="destructuring--object"></a><a name="5.1"></a>
462-
- [5.1](#destructuring--object) Use object destructuring when accessing and using multiple properties of an object. jscs: [`requireObjectDestructuring`](http://jscs.info/rule/requireObjectDestructuring)
462+
- [5.1](#destructuring--object) 当需要访问对象的多个属性时,使用解构。 jscs: [`requireObjectDestructuring`](http://jscs.info/rule/requireObjectDestructuring)
463463

464-
> Why? Destructuring saves you from creating temporary references for those properties.
464+
> Why? 解析可以避免创建临时变量。
465465

466466
```javascript
467467
// bad
@@ -485,7 +485,7 @@ Other Style Guides
485485
```
486486

487487
<a name="destructuring--array"></a><a name="5.2"></a>
488-
- [5.2](#destructuring--array) Use array destructuring. jscs: [`requireArrayDestructuring`](http://jscs.info/rule/requireArrayDestructuring)
488+
- [5.2](#destructuring--array) 使用数组解构. jscs: [`requireArrayDestructuring`](http://jscs.info/rule/requireArrayDestructuring)
489489

490490
```javascript
491491
const arr = [1, 2, 3, 4];
@@ -499,9 +499,9 @@ Other Style Guides
499499
```
500500

501501
<a name="destructuring--object-over-array"></a><a name="5.3"></a>
502-
- [5.3](#destructuring--object-over-array) Use object destructuring for multiple return values, not array destructuring. jscs: [`disallowArrayDestructuringReturn`](http://jscs.info/rule/disallowArrayDestructuringReturn)
502+
- [5.3](#destructuring--object-over-array) 当函数需要返回多个值时,使用对象解构,而非数组解构。 jscs: [`disallowArrayDestructuringReturn`](http://jscs.info/rule/disallowArrayDestructuringReturn)
503503

504-
> Why? You can add new properties over time or change the order of things without breaking call sites.
504+
> Why? 你可以随时添加新的属性,或者更改顺序,而不会影响调用方。
505505

506506
```javascript
507507
// bad
@@ -529,7 +529,7 @@ Other Style Guides
529529
## Strings
530530

531531
<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)
532+
- [6.1](#strings--quotes) 使用单引号 `''` eslint: [`quotes`](http://eslint.org/docs/rules/quotes.html) jscs: [`validateQuoteMarks`](http://jscs.info/rule/validateQuoteMarks)
533533

534534
```javascript
535535
// bad
@@ -543,9 +543,9 @@ Other Style Guides
543543
```
544544

545545
<a name="strings--line-length"></a><a name="6.2"></a>
546-
- [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.
546+
- [6.2](#strings--line-length) 超过100个字符的字符串不要使用字符连接符跨多行。
547547

548-
> Why? Broken strings are painful to work with and make code less searchable.
548+
> Why? 断字符串不容易使用,而且不容易搜索。
549549

550550
```javascript
551551
// bad
@@ -564,9 +564,9 @@ Other Style Guides
564564
```
565565

566566
<a name="es6-template-literals"></a><a name="6.4"></a>
567-
- [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)
567+
- [6.3](#es6-template-literals) 需要动态构建字符串时,使用模板,而不是字符串连接。 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)
568568

569-
> Why? Template strings give you a readable, concise syntax with proper newlines and string interpolation features.
569+
> Why? 模板字符串更易读。
570570

571571
```javascript
572572
// bad
@@ -591,12 +591,12 @@ Other Style Guides
591591
```
592592

593593
<a name="strings--eval"></a><a name="6.5"></a>
594-
- [6.4](#strings--eval) Never use `eval()` on a string, it opens too many vulnerabilities.
594+
- [6.4](#strings--eval) 永远不要对字符串使用 `eval()` , 太容易发生安全单一了.
595595

596596
<a name="strings--escaping"></a>
597-
- [6.5](#strings--escaping) Do not unnecessarily escape characters in strings. eslint: [`no-useless-escape`](http://eslint.org/docs/rules/no-useless-escape)
597+
- [6.5](#strings--escaping) 如非必要,不要转义字符。 eslint: [`no-useless-escape`](http://eslint.org/docs/rules/no-useless-escape)
598598

599-
> Why? Backslashes harm readability, thus they should only be present when necessary.
599+
> Why? 转义符影响阅读,所以只应该在必要时使用。
600600

601601
```javascript
602602
// bad

0 commit comments

Comments
 (0)