Skip to content

Commit 4ba665f

Browse files
author
zhangchunxiao
committed
more translation
1 parent ee4ce9e commit 4ba665f

File tree

1 file changed

+26
-27
lines changed

1 file changed

+26
-27
lines changed

README.md

Lines changed: 26 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -613,9 +613,9 @@ Other Style Guides
613613
## Functions
614614

615615
<a name="functions--declarations"></a><a name="7.1"></a>
616-
- [7.1](#functions--declarations) Use named function expressions instead of function declarations. eslint: [`func-style`](http://eslint.org/docs/rules/func-style) jscs: [`disallowFunctionDeclarations`](http://jscs.info/rule/disallowFunctionDeclarations)
616+
- [7.1](#functions--declarations) 使用命名的函数表达式,而不是函数声明。[O] eslint: [`func-style`](http://eslint.org/docs/rules/func-style) jscs: [`disallowFunctionDeclarations`](http://jscs.info/rule/disallowFunctionDeclarations)
617617

618-
> Why? Function declarations are hoisted, which means that it’s easy - too easy - to reference the function before it is defined in the file. This harms readability and maintainability. If you find that a function’s definition is large or complex enough that it is interfering with understanding the rest of the file, then perhaps it’s time to extract it to its own module! Don’t forget to name the expression - anonymous functions can make it harder to locate the problem in an Error's call stack. ([Discussion](https://github.com/airbnb/javascript/issues/794))
618+
> Why? 函数声明会被提前,所以太容易在函数定义前就开始引用了,这影响可读性及可维护性。如果一个函数太长或者太复杂,应该把它转移到独立的模块中。不要忘了给函数表达式命名,发生问题时匿名函数非常不容易debug. ([Discussion](https://github.com/airbnb/javascript/issues/794))
619619

620620
```javascript
621621
// bad
@@ -635,9 +635,9 @@ Other Style Guides
635635
```
636636

637637
<a name="functions--iife"></a><a name="7.2"></a>
638-
- [7.2](#functions--iife) Wrap immediately invoked function expressions in parentheses. eslint: [`wrap-iife`](http://eslint.org/docs/rules/wrap-iife.html) jscs: [`requireParenthesesAroundIIFE`](http://jscs.info/rule/requireParenthesesAroundIIFE)
638+
- [7.2](#functions--iife) 把立即调用的函数表达式(IIFE)放在括号中。 eslint: [`wrap-iife`](http://eslint.org/docs/rules/wrap-iife.html) jscs: [`requireParenthesesAroundIIFE`](http://jscs.info/rule/requireParenthesesAroundIIFE)
639639

640-
> Why? An immediately invoked function expression is a single unit - wrapping both it, and its invocation parens, in parens, cleanly expresses this. Note that in a world with modules everywhere, you almost never need an IIFE.
640+
> Why? IIFE 是一个独立的单元,所以把它以及调用放在括号中能很清楚地表达这一点。注意,在支持模块的环境中,基本不需要使用IIFE.
641641

642642
```javascript
643643
// immediately-invoked function expression (IIFE)
@@ -647,10 +647,10 @@ Other Style Guides
647647
```
648648

649649
<a name="functions--in-blocks"></a><a name="7.3"></a>
650-
- [7.3](#functions--in-blocks) Never declare a function in a non-function block (if, while, etc). Assign the function to a variable instead. Browsers will allow you to do it, but they all interpret it differently, which is bad news bears. eslint: [`no-loop-func`](http://eslint.org/docs/rules/no-loop-func.html)
650+
- [7.3](#functions--in-blocks) 不要在非函数代码块(if, while, etc)中声明函数,可以通过把函数赋值给变量。浏览器并不禁止这样做,但对这2种方式的解释方式是不一样的。 eslint: [`no-loop-func`](http://eslint.org/docs/rules/no-loop-func.html)
651651

652652
<a name="functions--note-on-blocks"></a><a name="7.4"></a>
653-
- [7.4](#functions--note-on-blocks) **Note:** ECMA-262 defines a `block` as a list of statements. A function declaration is not a statement. [Read ECMA-262's note on this issue](http://www.ecma-international.org/publications/files/ECMA-ST/Ecma-262.pdf#page=97).
653+
- [7.4](#functions--note-on-blocks) **Note:** ECMA-262 `` 定义为一段语句(statement)的集合。函数声明并不是语句(statement)。 [Read ECMA-262's note on this issue](http://www.ecma-international.org/publications/files/ECMA-ST/Ecma-262.pdf#page=97).
654654
655655
```javascript
656656
// bad
@@ -670,7 +670,7 @@ Other Style Guides
670670
```
671671
672672
<a name="functions--arguments-shadow"></a><a name="7.5"></a>
673-
- [7.5](#functions--arguments-shadow) Never name a parameter `arguments`. This will take precedence over the `arguments` object that is given to every function scope.
673+
- [7.5](#functions--arguments-shadow) 永远不要把参数命名为 `arguments`. 这会覆盖掉原有的 `arguments` 对象.
674674
675675
```javascript
676676
// bad
@@ -685,9 +685,9 @@ Other Style Guides
685685
```
686686
687687
<a name="es6-rest"></a><a name="7.6"></a>
688-
- [7.6](#es6-rest) Never use `arguments`, opt to use rest syntax `...` instead. eslint: [`prefer-rest-params`](http://eslint.org/docs/rules/prefer-rest-params)
688+
- [7.6](#es6-rest) 永远不要使用 `arguments`, 使用 rest 语法 `...`. eslint: [`prefer-rest-params`](http://eslint.org/docs/rules/prefer-rest-params)
689689
690-
> Why? `...` is explicit about which arguments you want pulled. Plus, rest arguments are a real Array, and not merely Array-like like `arguments`.
690+
> Why? `...` 显示地指明了你需要取哪些参数。同时,rest 参数是真正的数组,`arguments` 只是个类数组。
691691
692692
```javascript
693693
// bad
@@ -703,14 +703,13 @@ Other Style Guides
703703
```
704704
705705
<a name="es6-default-parameters"></a><a name="7.7"></a>
706-
- [7.7](#es6-default-parameters) Use default parameter syntax rather than mutating function arguments.
706+
- [7.7](#es6-default-parameters) 使用参数默认值而不是修改函数参数。
707707
708708
```javascript
709709
// really bad
710710
function handleThings(opts) {
711-
// No! We shouldn't mutate function arguments.
712-
// Double bad: if opts is falsy it'll be set to an object which may
713-
// be what you want but it can introduce subtle bugs.
711+
// 不要这样做!不应该改变函数参数
712+
// 另一个坏处: 如果 opts 判定为 false,这会把一个新对象赋值给它,这可能是你想要的,但容易引起别的bug
714713
opts = opts || {};
715714
// ...
716715
}
@@ -730,9 +729,9 @@ Other Style Guides
730729
```
731730
732731
<a name="functions--default-side-effects"></a><a name="7.8"></a>
733-
- [7.8](#functions--default-side-effects) Avoid side effects with default parameters.
732+
- [7.8](#functions--default-side-effects) 避免默认参数的副作用。
734733
735-
> Why? They are confusing to reason about.
734+
> Why? 影响可读性.
736735
737736
```javascript
738737
var b = 1;
@@ -747,7 +746,7 @@ Other Style Guides
747746
```
748747
749748
<a name="functions--defaults-last"></a><a name="7.9"></a>
750-
- [7.9](#functions--defaults-last) Always put default parameters last.
749+
- [7.9](#functions--defaults-last) 把默认参数放在最后。
751750
752751
```javascript
753752
// bad
@@ -762,9 +761,9 @@ Other Style Guides
762761
```
763762
764763
<a name="functions--constructor"></a><a name="7.10"></a>
765-
- [7.10](#functions--constructor) Never use the Function constructor to create a new function. eslint: [`no-new-func`](http://eslint.org/docs/rules/no-new-func)
764+
- [7.10](#functions--constructor) 不要使用构造函数创建新函数。 eslint: [`no-new-func`](http://eslint.org/docs/rules/no-new-func)
766765
767-
> Why? Creating a function in this way evaluates a string similarly to eval(), which opens vulnerabilities.
766+
> Why? 这样创建函数会执行字符串,这跟 eval() 类似,容易引起安全问题。
768767
769768
```javascript
770769
// bad
@@ -775,9 +774,9 @@ Other Style Guides
775774
```
776775
777776
<a name="functions--signature-spacing"></a><a name="7.11"></a>
778-
- [7.11](#functions--signature-spacing) Spacing in a function signature. eslint: [`space-before-function-paren`](http://eslint.org/docs/rules/space-before-function-paren) [`space-before-blocks`](http://eslint.org/docs/rules/space-before-blocks)
777+
- [7.11](#functions--signature-spacing) 函数签名用空格格开。 eslint: [`space-before-function-paren`](http://eslint.org/docs/rules/space-before-function-paren) [`space-before-blocks`](http://eslint.org/docs/rules/space-before-blocks)
779778
780-
> Why? Consistency is good, and you shouldn’t have to add or remove a space when adding or removing a name.
779+
> Why? 保持一致性,并且在添加或删除命名时不需要添加或删除空格。
781780
782781
```javascript
783782
// bad
@@ -791,9 +790,9 @@ Other Style Guides
791790
```
792791
793792
<a name="functions--mutate-params"></a><a name="7.12"></a>
794-
- [7.12](#functions--mutate-params) Never mutate parameters. eslint: [`no-param-reassign`](http://eslint.org/docs/rules/no-param-reassign.html)
793+
- [7.12](#functions--mutate-params) 永远不要更改函数参数。 eslint: [`no-param-reassign`](http://eslint.org/docs/rules/no-param-reassign.html)
795794
796-
> Why? Manipulating objects passed in as parameters can cause unwanted variable side effects in the original caller.
795+
> Why? 操作传过来的对象可能引起副作用,从而影响到调用者。
797796
798797
```javascript
799798
// bad
@@ -808,9 +807,9 @@ Other Style Guides
808807
```
809808
810809
<a name="functions--reassign-params"></a><a name="7.13"></a>
811-
- [7.13](#functions--reassign-params) Never reassign parameters. eslint: [`no-param-reassign`](http://eslint.org/docs/rules/no-param-reassign.html)
810+
- [7.13](#functions--reassign-params) 永远不要给参数重新赋值。 eslint: [`no-param-reassign`](http://eslint.org/docs/rules/no-param-reassign.html)
812811
813-
> Why? Reassigning parameters can lead to unexpected behavior, especially when accessing the `arguments` object. It can also cause optimization issues, especially in V8.
812+
> Why? 给参数重新赋值会引起意想不到的结果,尤其是在访问 `arguments` 时。这也会影响性能优化,尤其是在V8中。
814813
815814
```javascript
816815
// bad
@@ -836,9 +835,9 @@ Other Style Guides
836835
```
837836
838837
<a name="functions--spread-vs-apply"></a><a name="7.14"></a>
839-
- [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)
838+
- [7.14](#functions--spread-vs-apply) 推荐使用 spread operator `...` 来调用可变参数函数。 eslint: [`prefer-spread`](http://eslint.org/docs/rules/prefer-spread)
840839
841-
> Why? It's cleaner, you don't need to supply a context, and you can not easily compose `new` with `apply`.
840+
> Why? 更清楚,不需要提供context,并且用 `apply` 去构建 `new` 时并不容易。
842841
843842
```javascript
844843
// bad
@@ -857,7 +856,7 @@ Other Style Guides
857856
```
858857
859858
<a name="functions--signature-invocation-indentation"></a>
860-
- [7.15](#functions--signature-invocation-indentation) Functions with multiline signatures, or invocations, should be indented just like every other multiline list in this guide: with each item on a line by itself, with a trailing comma on the last item.
859+
- [7.15](#functions--signature-invocation-indentation) 函数签名需要跨多行,或者调用时需要跨多行时,遵循其它多行原则:每一项新起一行,在最后一项尾部添加逗号。
861860
862861
```javascript
863862
// bad

0 commit comments

Comments
 (0)