Skip to content

Commit 57904c5

Browse files
Starriersleviding
authored andcommitted
Translation/dom node properties (javascript-tutorial#153)
* 翻译完成 * 翻译完成 * 翻译完成 * 翻译完成 * 翻译完成 * 翻译完成 * 翻译完成 * The First Modification * The First Modification * Update solution.md * Update article.md
1 parent c8626b9 commit 57904c5

File tree

7 files changed

+169
-169
lines changed

7 files changed

+169
-169
lines changed

2-ui/1-document/05-basic-dom-node-properties/2-lastchild-nodetype-inline/solution.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
There's a catch here.
1+
这里有一个陷阱。
22

3-
At the time of `<script>` execution the last DOM node is exactly `<script>`, because the browser did not process the rest of the page yet.
3+
在执行 `<script>` 时,最后一个 DOM 节点是 `<script>`,因为浏览器还没有处理页面的其余部分。
44

5-
So the result is `1` (element node).
5+
因此结果是 `1`(元素节点)。
66

77
```html run height=60
88
<html>

2-ui/1-document/05-basic-dom-node-properties/2-lastchild-nodetype-inline/task.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@ importance: 5
22

33
---
44

5-
# What's in the nodeType?
5+
# nodeType 是什么?
66

7-
What does the script show?
7+
脚本会显示什么?
88

99
```html
1010
<html>
Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
The answer: **`BODY`**.
1+
答案是:**`BODY`**
22

33
```html run
44
<script>
@@ -10,8 +10,8 @@ The answer: **`BODY`**.
1010
</script>
1111
```
1212

13-
What's going on step by step:
13+
这几步都发生了什么:
1414

15-
1. The content of `<body>` is replaced with the comment. The comment is <code>&lt;!--BODY--&gt;</code>, because `body.tagName == "BODY"`. As we remember, `tagName` is always uppercase in HTML.
16-
2. The comment is now the only child node, so we get it in `body.firstChild`.
17-
3. The `data` property of the comment is its contents (inside `<!--...-->`): `"BODY"`.
15+
1. `<body>` 内容被注释所取代 <code>&lt;!--BODY--&gt;</code>,因为 `body.tagName == "BODY"`。正如我们所记住的,`tagName` HTML 中总是大写的。
16+
2. 这个注释现在是唯一的子节点,所以我们可以在 `body.firstChild` 中获取。
17+
3. 注释的`data` 属性是它的内容 (inside `<!--...-->`)`"BODY"`

2-ui/1-document/05-basic-dom-node-properties/3-tag-in-comment/task.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@ importance: 3
22

33
---
44

5-
# Tag in comment
5+
# 注释中的标记
66

7-
What does this code show?
7+
这个代码会显示什么?
88

99
```html
1010
<script>
Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,38 @@
11

2-
We can see which class it belongs by outputting it, like:
2+
通过输出它,我们可以看到它属于哪个类,比如:
33

44
```js run
55
alert(document); // [object HTMLDocument]
66
```
77

8-
Or:
8+
或者:
99

1010
```js run
1111
alert(document.constructor.name); // HTMLDocument
1212
```
1313

14-
So, `document` is an instance of `HTMLDocument` class.
14+
因此 `document` `HTMLDocument` 类的一个实例。
1515

16-
What's its place in the hierarchy?
16+
它在等级体系中的地位如何?
1717

18-
Yeah, we could browse the specification, but it would be faster to figure out manually.
18+
是的,我们可以浏览说明书,但手动会更快。
1919

20-
Let's traverse the prototype chain via `__proto__`.
20+
我们通过 `__proto__` 来遍历原型链中的方法。
2121

22-
As we know, methods of a class are in the `prototype` of the constructor. For instance, `HTMLDocument.prototype` has methods for documents.
22+
正如我们所知道的,类的方法在构造函数的 `prototype` 中。例如 `HTMLDocument.prototype` 有用于文档的方法。
2323

24-
Also, there's a reference to the constructor function inside the `prototype`:
24+
此外,在 `prototype` 中还有对构造函数的引用:
2525

2626
```js run
2727
alert(HTMLDocument.prototype.constructor === HTMLDocument); // true
2828
```
2929

30-
For built-in classes in all prototypes there's a `constructor` reference, and we can get `constructor.name` to see the name of the class. Let's do it for all objects in the `document` prototype chain:
30+
对于所有原型中的内置类,有一个 `constructor` 引用,我们可以获取 `constructor.name` 来查看类名。我们为 `document` 原型链中的所有对象执行以下操作:
3131

3232
```js run
3333
alert(HTMLDocument.prototype.constructor.name); // HTMLDocument
3434
alert(HTMLDocument.prototype.__proto__.constructor.name); // Document
3535
alert(HTMLDocument.prototype.__proto__.__proto__.constructor.name); // Node
3636
```
3737

38-
We also could examine the object using `console.dir(document)` and see these names by opening `__proto__`. The console takes them from `constructor` internally.
38+
我们还可以使用 `console.dir(document)` 来检查对象,并通过打开 `__proto__` 来查看这些名称。控制台将它们从 `constructor` 内部取出。

2-ui/1-document/05-basic-dom-node-properties/4-where-document-in-hierarchy/task.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@ importance: 4
22

33
---
44

5-
# Where's the "document" in the hierarchy?
5+
# 层次结构中的 "document" 在哪里?
66

7-
Which class does the `document` belong to?
7+
`document` 属于哪一类?
88

9-
What's its place in the DOM hierarchy?
9+
DOM 层次中它的位置又如何?
1010

11-
Does it inherit from `Node` or `Element`, or maybe `HTMLElement`?
11+
它继承自 `Node` `Element`,还是 `HTMLElement`

0 commit comments

Comments
 (0)