Skip to content

Commit a7d0388

Browse files
DJ-YangViolet-Bora-Lee
authored andcommitted
#471 [주요 노드 프로퍼티] 과제4, 문제 번역 (#481)
1 parent 4e3a2c8 commit a7d0388

File tree

1 file changed

+11
-11
lines changed
  • 2-ui/1-document/05-basic-dom-node-properties/4-where-document-in-hierarchy

1 file changed

+11
-11
lines changed
Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,40 @@
11

2-
We can see which class it belongs by outputting it, like:
2+
`document` 노드가 어떤 클래스에 속해있는지는 아래와 같은 스크립트를 통해 확인할 수 있습니다.
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+
그렇다면 `HTMLDocument` 클래스는 DOM 계층 구조에서 어디에 있을까요?
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`에 구현되어있습니다. `document`의 메서드는 `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-
To get a name of the class as a string, we can use `constructor.name`. Let's do it for the whole `document` prototype chain, till class `Node`:
30+
클래스 이름을 얻으려면 `constructor.name`를 사용하면 됩니다. `Node` 클래스를 만날 때까지 `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-
That's the hierarchy.
38+
위와 같은 코드를 사용해 계층 구조를 파악할 수 있습니다.
3939

40-
We also could examine the object using `console.dir(document)` and see these names by opening `__proto__`. The console takes them from `constructor` internally.
40+
이 외에도 개발자 도구에서 `console.dir(document)`를 사용해 객체를 검사하고, `__proto__`에 저장된 정보를 통해 이름을 알아낼 수도 있습니다. 브라우저 콘솔 내부에서 자동으로 `constructor`의 이름을 추출하기 때문입니다.

0 commit comments

Comments
 (0)