Skip to content

Commit c1c61c3

Browse files
authoredJul 23, 2020
Translate some chapters to [Jul 17, 2020] part4 (#801)
Translate some chapters to [Jul 17, 2020] part4 (#801)
1 parent 3989208 commit c1c61c3

File tree

4 files changed

+22
-22
lines changed

4 files changed

+22
-22
lines changed
 

‎1-js/05-data-types/10-destructuring-assignment/article.md

+6-6
Original file line numberDiff line numberDiff line change
@@ -122,22 +122,22 @@ for (let [key, value] of user) {
122122
```
123123
````
124124

125-
```smart header="Swap variables trick"
126-
A well-known trick for swapping values of two variables:
125+
```smart header="交换变量值的技巧"
126+
一个用于交换变量值的典型技巧:
127127
128128
```js run
129129
let guest = "Jane";
130130
let admin = "Pete";
131131
132-
// Swap values: make guest=Pete, admin=Jane
132+
// 交换值:让 guest=Pete, admin=Jane
133133
[guest, admin] = [admin, guest];
134134
135-
alert(`${guest} ${admin}`); // Pete Jane (successfully swapped!)
135+
alert(`${guest} ${admin}`); // Pete Jane(成功交换!)
136136
```
137137

138-
Here we create a temporary array of two variables and immediately destructure it in swapped order.
138+
这里我们创建了一个由两个变量组成的临时数组,并且立即以交换了的顺序对其进行了解构。
139139

140-
We can swap more than two variables this way.
140+
我们可以用这种方式交换两个以上的变量。
141141

142142

143143
### 剩余的 '...'

‎1-js/06-advanced-functions/04-var/article.md

+11-11
Original file line numberDiff line numberDiff line change
@@ -13,18 +13,18 @@
1313
2. `const`
1414
3. `var`
1515

16-
The `var` declaration is similar to `let`. Most of the time we can replace `let` by `var` or vice-versa and expect things to work:
16+
`var` 声明与 `let` 相似。大部分情况下,我们可以用 `let` 代替 `var` 或者 `var` 代替 `let`,都能达到预期的效果:
1717

1818
```js run
1919
var message = "Hi";
2020
alert(message); // Hi
2121
```
2222

23-
But internally `var` is a very different beast, that originates from very old times. It's generally not used in modern scripts, but still lurks in the old ones.
23+
但实际上 `var` 却是一头非常不同的,源自远古时代的怪兽。在现代脚本中一般不再使用它,但它仍然潜伏在旧脚本中。
2424

25-
If you don't plan on meeting such scripts you may even skip this chapter or postpone it.
25+
如果你不打算接触这样的脚本,你甚至可以跳过本章或推迟阅读本章。
2626

27-
On the other hand, it's important to understand differences when migrating old scripts from `var` to `let`, to avoid odd errors.
27+
另一方面,了解将旧脚本从 `var` 迁移到 `let` 时的区别,以避免奇怪的错误,是很重要的。
2828

2929
## "var" 没有块级作用域
3030

@@ -80,32 +80,32 @@ function sayHi() {
8080
}
8181

8282
sayHi();
83-
alert(phrase); // Error: phrase is not defined (Check the Developer Console)
83+
alert(phrase); // Error: phrase is not defined(检查开发者控制台)
8484
```
8585

8686
可以看到,`var` 穿透了 `if``for` 和其它代码块。这是因为在早期的 JavaScript 中,块没有词法环境。而 `var` 就是这个时期的代表之一。
8787

8888
## "var" 允许重新声明
8989

90-
If we declare the same variable with `let` twice in the same scope, that's an error:
90+
如果我们用 `let` 在同一作用域下将同一个变量声明两次,则会出现错误:
9191

9292
```js run
9393
let user;
9494
let user; // SyntaxError: 'user' has already been declared
9595
```
9696

97-
With `var`, we can redeclare a variable any number of times. If we use `var` with an already-declared variable, it's just ignored:
97+
使用 `var`,我们可以重复声明一个变量,不管多少次都行。如果我们对一个已经声明的变量使用 `var`,这条新的声明语句会被忽略:
9898

9999
```js run
100100
var user = "Pete";
101101

102-
var user = "John"; // this "var" does nothing (already declared)
103-
// ...it doesn't trigger an error
102+
var user = "John"; // 这个 "var" 无效(因为变量已经声明过了)
103+
// ……不会触发错误
104104

105105
alert(user); // John
106106
```
107107

108-
## "var" variables can be declared below their use
108+
## "var" 声明的变量,可以在其声明语句前被使用
109109

110110
当函数开始的时候,就会处理 `var` 声明(脚本启动对应全局变量)。
111111

@@ -126,7 +126,7 @@ function sayHi() {
126126
sayHi();
127127
```
128128

129-
……从技术上将,它与下面这种情况是一样的(`var phrase` 被上移至函数开头):
129+
……从技术上讲,它与下面这种情况是一样的(`var phrase` 被上移至函数开头):
130130

131131
```js run
132132
function sayHi() {

‎1-js/06-advanced-functions/09-call-apply-decorators/04-throttle/task.md

+4-4
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@ importance: 5
66

77
创建一个“节流”装饰者 `throttle(f, ms)` —— 返回一个包装器。
88

9-
When it's called multiple times, it passes the call to `f` at maximum once per `ms` milliseconds.
9+
当被多次调用时,它会在每 `ms` 毫秒最多将调用传递给 `f` 一次。
1010

11-
The difference with debounce is that it's completely different decorator:
12-
- `debounce` runs the function once after the "cooldown" period. Good for processing the final result.
13-
- `throttle` runs it not more often than given `ms` time. Good for regular updates that shouldn't be very often.
11+
与去抖的不同是,它是个完全不同的装饰器:
12+
- `debounce` 会在“冷却(cooldown)”期后运行函数一次。适用于处理最终结果。
13+
- `throttle` 运行函数的频率不会大于所给定的时间 `ms` 毫秒。适用于不应该经常进行的定期更新。
1414

1515
让我们看看现实生活中的应用程序,以便更好地理解这个需求,并了解它的来源。
1616

‎1-js/06-advanced-functions/09-call-apply-decorators/article.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,7 @@ worker.slow = cachingDecorator(worker.slow);
236236

237237
对于许多实际应用,第三种方式就足够了,所以我们就用这个吧。
238238

239-
Also we need to pass not just `x`, but all arguments in `func.call`. Let's recall that in a `function()` we can get a pseudo-array of its arguments as `arguments`, so `func.call(this, x)` should be replaced with `func.call(this, ...arguments)`.
239+
当然,我们需要传入的不仅是 `x`,还需要传入 `func.call` 的所有参数。让我们回想一下,在 `function()` 中我们可以得到一个包含所有参数的伪数组(pseudo-array`arguments`,那么 `func.call(this, x)` 应该被替换为 `func.call(this, ...arguments)`
240240

241241
这是一个更强大的 `cachingDecorator`
242242

0 commit comments

Comments
 (0)
Please sign in to comment.