Skip to content

Commit ea97755

Browse files
committed
feat: update translation
1 parent 49a00cf commit ea97755

File tree

18 files changed

+104
-28
lines changed

18 files changed

+104
-28
lines changed

1-js/09-classes/03-static-properties-methods/article.md

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11

22
# 静态属性和静态方法
33

4-
我们可以把一个方法赋值给类的函数本身,而不是赋给它的 `"prototype"`。这样的方法被称为 **静态的(static)**
4+
我们可以把一个方法作为一个整体赋值给类。这样的方法被称为 **静态的(static)**
55

6-
在一个类中,它们以 `static` 关键字开头,如下所示:
6+
在一个类的声明中,它们以 `static` 关键字开头,如下所示:
77

88
```js run
99
class User {
@@ -31,9 +31,11 @@ User.staticMethod(); // true
3131

3232
`User.staticMethod()` 调用中的 `this` 的值是类构造器 `User` 自身(“点符号前面的对象”规则)。
3333

34-
通常,静态方法用于实现属于该类但不属于该类任何特定对象的函数
34+
通常,静态方法用于实现属于整个类,但不属于该类任何特定对象的函数
3535

36-
例如,我们有对象 `Article`,并且需要一个方法来比较它们。一个自然的解决方案就是添加 `Article.compare` 方法,像下面这样:
36+
例如,我们有对象 `Article`,并且需要一个方法来比较它们。
37+
38+
通常的解决方案就是添加 `Article.compare` 静态方法:
3739

3840
```js run
3941
class Article {
@@ -63,17 +65,19 @@ articles.sort(Article.compare);
6365
alert( articles[0].title ); // CSS
6466
```
6567

66-
这里 `Article.compare` 代表“上面的”文章,意思是比较它们。它不是文章的方法,而是整个 class 的方法。
68+
这里 `Article.compare` 方法代表“上面的”文章,意思是比较它们。它不是文章的方法,而是整个 class 的方法。
69+
70+
另一个例子是所谓的“工厂”方法。
6771

68-
另一个例子是所谓的“工厂”方法。想象一下,我们需要通过几种方法来创建一个文章
72+
比如说,我们需要通过多种方式来创建一篇文章
6973

7074
1. 通过用给定的参数来创建(`title``date` 等)。
7175
2. 使用今天的日期来创建一个空的文章。
7276
3. ……其它方法。
7377

7478
第一种方法我们可以通过 constructor 来实现。对于第二种方式,我们可以创建类的一个静态方法来实现。
7579

76-
就像这里的 `Article.createTodays()`
80+
例如这里的 `Article.createTodays()`
7781

7882
```js run
7983
class Article {
@@ -101,7 +105,7 @@ alert( article.title ); // Today's digest
101105

102106
```js
103107
// 假定 Article 是一个用来管理文章的特殊类
104-
// 静态方法用于移除文章
108+
// 通过 id 来移除文章的静态方法
105109
Article.remove({id: 12345});
106110
```
107111

1-js/11-async/05-promise-api/article.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,10 @@
1313
语法:
1414

1515
```js
16-
let promise = Promise.all([...promises...]);
16+
let promise = Promise.all(iterable);
1717
```
1818

19-
`Promise.all` 接受一个 promise 数组作为参数(从技术上讲,它可以是任何可迭代对象,但通常是一个数组)并返回一个新的 promise。
19+
`Promise.all` 接受一个可迭代对象(通常是一个数组项为 promise 的数组),并返回一个新的 promise。
2020

2121
当所有给定的 promise 都 resolve 时,新的 promise 才会 resolve,并且其结果数组将成为新 promise 的结果。
2222

@@ -248,7 +248,7 @@ Promise.any([
248248
]).catch(error => {
249249
console.log(error.constructor.name); // AggregateError
250250
console.log(error.errors[0]); // Error: Ouch!
251-
console.log(error.errors[1]); // Error: Error
251+
console.log(error.errors[1]); // Error: Error!
252252
});
253253
```
254254

1-js/11-async/08-async-await/01-rewrite-async/solution.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ async function loadJson(url) { // (1)
1313
throw new Error(response.status);
1414
}
1515

16-
loadJson('no-such-user.json')
16+
loadJson('https://javascript.info/no-such-user.json')
1717
.catch(alert); // Error: 404 (4)
1818
```
1919

1-js/11-async/08-async-await/01-rewrite-async/task.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,6 @@ function loadJson(url) {
1515
});
1616
}
1717

18-
loadJson('no-such-user.json')
18+
loadJson('https://javascript.info/no-such-user.json')
1919
.catch(alert); // Error: 404
2020
```

1-js/13-modules/02-import-export/article.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ say.sayBye('John');
9393

9494
这里有几个原因。
9595

96-
1. 现代的构建工具([webpack](http://webpack.github.io) 和其他工具)将模块打包到一起并对其进行优化,以加快加载速度并删除未使用的代码。
96+
1. 现代的构建工具([webpack](https://webpack.js.org/) 和其他工具)将模块打包到一起并对其进行优化,以加快加载速度并删除未使用的代码。
9797

9898
比如说,我们向我们的项目里添加一个第三方库 `say.js`,它具有许多函数:
9999
```js

1-js/99-js-misc/04-reference-type/article.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ user.hi();
5959
let user = {
6060
name: "John",
6161
hi() { alert(this.name); }
62-
}
62+
};
6363

6464
*!*
6565
// 把获取方法和调用方法拆成两行

2-ui/1-document/04-searching-elements-dom/article.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ CSS 选择器的伪类,例如 `:hover` 和 `:active` 也都是被支持的。
154154
<div class="contents">
155155
<ul class="book">
156156
<li class="chapter">Chapter 1</li>
157-
<li class="chapter">Chapter 1</li>
157+
<li class="chapter">Chapter 2</li>
158158
</ul>
159159
</div>
160160

2-ui/1-document/09-size-and-scroll/article.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ JavaScript 中有许多属性可让我们读取有关元素宽度、高度和其
1717
width: 300px;
1818
height: 200px;
1919
border: 25px solid #E8C48F;
20-
padding: 20px;
21-
overflow: auto;
20+
padding: 20px;
21+
overflow: auto;
2222
}
2323
</style>
2424
```

2-ui/1-document/09-size-and-scroll/metric-client-left-top-rtl.svg

Lines changed: 1 addition & 1 deletion
Loading
Lines changed: 1 addition & 1 deletion
Loading

2-ui/3-event-details/4-mouse-drag-and-drop/article.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ ball.onmousedown = function(event) {
3030

3131
// 将其从当前父元素中直接移动到 body 中
3232
// 以使其定位是相对于 body 的
33-
document.body.append(ball);
33+
document.body.append(ball);
3434

3535
// 现在球的中心在 (pageX, pageY) 坐标上
3636
function moveAt(pageX, pageY) {
@@ -219,7 +219,7 @@ In action (inside `<iframe>`):
219219

220220
那么,该怎么办?
221221

222-
有一个叫做 `document.elementFromPoint(clientX, clientY)` 的方法。它会返回在给定的窗口相对坐标处的嵌套的最深的元素(如果给定的坐标在窗口外,则返回 `null`)。
222+
有一个叫做 `document.elementFromPoint(clientX, clientY)` 的方法。它会返回在给定的窗口相对坐标处的嵌套的最深的元素(如果给定的坐标在窗口外,则返回 `null`)。如果同一坐标上有多个重叠的元素,则返回最上面的元素。
223223

224224
我们可以在我们的任何鼠标事件处理程序中使用它,以检测鼠标指针下的潜在的 "droppable" 的元素,就像这样:
225225

2-ui/4-forms-controls/1-form-elements/article.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ alert(ageElems[0]); // [object HTMLInputElement]
155155
156156
### input 和 textarea
157157
158-
我们可以通过 `input.value`(字符串)或 `input.checked`(布尔值)来访问复选框(checkbox)中的它们的 `value`。
158+
我们可以通过 `input.value`(字符串)或 `input.checked`(布尔值)来访问复选框(checkbox)和单选按钮(radio button)中的 `value`。
159159
160160
像这样:
161161
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
The console output is: 1 7 3 5 2 6 4.
2+
3+
The task is quite simple, we just need to know how microtask and macrotask queues work.
4+
5+
Let's see what's going on, step by step.
6+
7+
```js
8+
console.log(1);
9+
// The first line executes immediately, it outputs `1`.
10+
// Macrotask and microtask queues are empty, as of now.
11+
12+
setTimeout(() => console.log(2));
13+
// `setTimeout` appends the callback to the macrotask queue.
14+
// - macrotask queue content:
15+
// `console.log(2)`
16+
17+
Promise.resolve().then(() => console.log(3));
18+
// The callback is appended to the microtask queue.
19+
// - microtask queue content:
20+
// `console.log(3)`
21+
22+
Promise.resolve().then(() => setTimeout(() => console.log(4)));
23+
// The callback with `setTimeout(...4)` is appended to microtasks
24+
// - microtask queue content:
25+
// `console.log(3); setTimeout(...4)`
26+
27+
Promise.resolve().then(() => console.log(5));
28+
// The callback is appended to the microtask queue
29+
// - microtask queue content:
30+
// `console.log(3); setTimeout(...4); console.log(5)`
31+
32+
setTimeout(() => console.log(6));
33+
// `setTimeout` appends the callback to macrotasks
34+
// - macrotask queue content:
35+
// `console.log(2); console.log(6)`
36+
37+
console.log(7);
38+
// Outputs 7 immediately.
39+
```
40+
41+
To summarize,
42+
43+
1. Numbers `1` и `7` show up immediately, because simple `console.log` calls don't use any queues.
44+
2. Then, after the main code flow is finished, the microtask queue runs.
45+
- It has commands: `console.log(3); setTimeout(...4); console.log(5)`.
46+
- Numbers `3` и `5` show up, while `setTimeout(() => console.log(4))` adds the `console.log(4)` call to the end of the macrotask queue.
47+
- The macrotask queue is now: `console.log(2); console.log(6); console.log(4)`.
48+
3. After the microtask queue becomes empty, the macrotask queue executes. It outputs `2`, `6`, `4`.
49+
50+
Finally, we have the output: `1 7 3 5 2 6 4`.
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
importance: 5
2+
3+
---
4+
5+
# 下方这段代码的输出是什么?
6+
7+
```js
8+
console.log(1);
9+
10+
setTimeout(() => console.log(2));
11+
12+
Promise.resolve().then(() => console.log(3));
13+
14+
Promise.resolve().then(() => setTimeout(() => console.log(4)));
15+
16+
Promise.resolve().then(() => console.log(5));
17+
18+
setTimeout(() => console.log(6));
19+
20+
console.log(7);
21+
```

3-frames-and-windows/01-popup-windows/article.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,7 @@ window.onblur = () => window.focus();
260260
- 当我们打开一个弹窗时,在它上面执行 `newWindow.focus()` 是个好主意。以防万一,对于某些操作系统/浏览器组合(combination),它可以确保用户现在位于新窗口中。
261261
- 如果我们想要跟踪访问者何时在实际使用我们的 Web 应用程序,我们可以跟踪 `window.onfocus/onblur`。这使我们可以暂停/恢复页面活动和动画等。但是请注意,`blur` 事件意味着访问者从窗口切换了出来,但他们仍然可以观察到它。窗口处在背景中,但可能仍然是可见的。
262262

263-
## 总结
263+
## 总结
264264

265265
弹窗很少使用,因为有其他选择:在页面内或在 iframe 中加载和显示信息。
266266

4-binary/01-arraybuffer-binary-arrays/01-concat/_js.view/solution.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@ function concat(arrays) {
22
// sum of individual array lengths
33
let totalLength = arrays.reduce((acc, value) => acc + value.length, 0);
44

5-
if (!arrays.length) return null;
6-
75
let result = new Uint8Array(totalLength);
86

7+
if (!arrays.length) return result;
8+
99
// for each array - copy it over result
1010
// next array is copied right after the previous one
1111
let length = 0;

0 commit comments

Comments
 (0)