Skip to content

Commit 889d204

Browse files
committed
100% translate to chinese
1 parent 5824b51 commit 889d204

File tree

3 files changed

+39
-24
lines changed

3 files changed

+39
-24
lines changed

src/SUMMARY.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,18 +24,18 @@
2424
- [(D) 定时器或时钟](pages/keywords-syntax-comparison/README.md#d-定时器或时钟)
2525
- [(D) 字符串常量](pages/keywords-syntax-comparison/README.md#d-字符串常量)
2626
- [(S) 注释](pages/keywords-syntax-comparison/README.md#s-注释)
27-
- [类型](pages/types/README.md)
27+
- [流程控制语句](pages/types/README.md)
2828
- [(D) 值,指针,引用](pages/types/README.md#d-值,指针,引用)
2929
- [(D) 数组 / 切片](pages/types/README.md#d-数组--切片)
3030
- [(D) 字典](pages/types/README.md#d-字典)
3131
- [(D) 集合](pages/types/README.md#d-集合)
32-
- [Flow control statements](pages/flow-control-statements/README.md)
33-
- [(B) Loops and iteration](pages/flow-control-statements/README.md#b-loops-and-iteration)
32+
- [流控制](pages/flow-control-statements/README.md)
33+
- [(B) 循环和迭代](pages/flow-control-statements/README.md#b-循环和迭代)
3434
- [(B) If/Else](pages/flow-control-statements/README.md#b-ifelse)
3535
- [(D) Switch](pages/flow-control-statements/README.md#d-switch)
36-
- [Functions](pages/functions/README.md)
37-
- [(S) first-class functions](pages/functions/README.md#s-first-class-functions)
38-
- [(D) Multiple returns](pages/functions/README.md#d-multiple-returns)
36+
- [函数](pages/functions/README.md)
37+
- [(S) 一级函数](pages/functions/README.md#s-一级函数)
38+
- [(D) 多返回值](pages/functions/README.md#d-多返回值)
3939
- [(S) IIFE](pages/functions/README.md#s-iife)
40-
- [(S) Closures](pages/functions/README.md#s-closures)
40+
- [(S) 闭包](pages/functions/README.md#s-闭包)
4141
- [License](pages/license/README.md)

src/pages/flow-control-statements/README.md

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
# Flow control statements
2-
## (B) Loops and iteration
1+
# 流程控制语句
2+
## (B) 循环和迭代
33
### For
44
**JS**
55
```Javascript
@@ -16,7 +16,9 @@ for i := 0; i < 10; i++ {
1616
```
1717

1818
### While
19-
In Go, the `for`'s init and post statement are optional, effectively making it also a "while" statement:
19+
20+
在Go中,`for`的初始化和过程语句是可选的,实际上它也是一个“while”语句
21+
2022

2123
**JS**
2224
```Javascript
@@ -35,7 +37,7 @@ for i < 10 {
3537
i++
3638
}
3739
```
38-
### Iterating over an Array/Slice
40+
### 遍历一个 Array或Slice
3941

4042
**JS**
4143
```Javascript
@@ -53,7 +55,9 @@ for i, v := range []string{"Rick", "Morty", "Beth", "Summer", "Jerry"} {
5355

5456

5557
## (B) If/Else
56-
Go's `if` can contain an init statement, with variables declared scoped only to the `if` and `else` blocks.
58+
59+
Go的 `if` 可以包含初始化语句,里面的变量声明的作用域是 `if``else`的块中。
60+
5761

5862
**Go**
5963
```Go
@@ -65,11 +69,14 @@ if value := getSomeValue(); value < limit {
6569
```
6670

6771
## (D) Switch
68-
The switch statement was one of the motivation for writing this document.
6972

70-
Go defaults to break, and `fallthrough` needed for otherwise.
73+
swtich语句是写这篇文档的动机之一。
74+
75+
Go默认break,否则需要使用`fallthrough`
76+
77+
Javascript 默认是 fallthrough,否则需要使用 `break`
7178

72-
Javascript defaults to fallthrough, and `break` needed for otherwise.
79+
(译者注: fallthrough指的是自动执行下一条条件语句)
7380

7481
**JS**
7582
```Javascript

src/pages/functions/README.md

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
1-
# Functions
2-
## (S) first-class functions
3-
Both languages treat functions as first-class citizens. Both allow functions to be passed as arguments, to be a returned value, to be nested, and have closures.
1+
# 函数
2+
## (S) 一级函数
43

5-
Function nesting in Javascript can be done both with named and anonymous functions, while in Go this can only be done with anonymous functions.
4+
两种语言都把函数视为一级函数成员。都允许函数当做参数传递,或者当做返回值,或者嵌套,或者闭包
65

7-
## (D) Multiple returns
8-
Go functions can return multiple values
6+
嵌套函数在Javascript中可以被命名或者是匿名函数,而Go中只能是匿名函数
7+
8+
9+
## (D) 多返回值
10+
11+
Go函数可以返回多个值
912

1013
**Go**
1114
```Go
@@ -18,7 +21,9 @@ func main() {
1821
fmt.Println(a, b)
1922
}
2023
```
21-
Javascript cannot, however by using destructuring assignment syntax, we can get a similar behavior
24+
25+
Javascript不能使用多返回值的语法,我们可以做一个类似的形式
26+
2227

2328
**JS**
2429
```Javascript
@@ -32,6 +37,8 @@ console.log(a,b);
3237

3338
## (S) IIFE
3439

40+
(译者注: Immediately Invoked Function Expression 立即调用的函数表达式)
41+
3542
**JS**
3643
```Javascript
3744
(function () {
@@ -48,8 +55,9 @@ func main() {
4855
}
4956
```
5057

51-
## (S) Closures
52-
Both languages have closures. Both require caution when [creating closures inside loops](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Closures#Creating_closures_in_loops_A_common_mistake). Here are examples in both languages that demonstrate a similar technique to bypass the closure/loop trap:
58+
## (S) 闭包
59+
60+
两种语言都支持闭包,都需要注意的是当[在循环中使用闭包](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Closures#Creating_closures_in_loops_A_common_mistake). 以下是两种语言的示例,演示了绕过闭包/循环"陷阱"的方式:
5361

5462
**JS (with bug)**
5563
```Javascript

0 commit comments

Comments
 (0)