Skip to content

Commit 4bf3a61

Browse files
sooyun429bumkeyy
andauthored
translate dom-manipulation The Node interface #117 (#157)
* translate dom-manipulation The Node interface #117 * Update pages/tutorials/dom-manipulation.md Co-authored-by: Kibeom Kwon <[email protected]> * Update pages/tutorials/dom-manipulation.md Co-authored-by: Kibeom Kwon <[email protected]> * Update pages/tutorials/dom-manipulation.md Co-authored-by: Kibeom Kwon <[email protected]>
1 parent 3f967b4 commit 4bf3a61

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

Diff for: β€Žpages/tutorials/dom-manipulation.md

+4-4
Original file line numberDiff line numberDiff line change
@@ -101,19 +101,19 @@ interface HTMLElementTagNameMap {
101101

102102
이제, `createElement` μ •μ˜μ˜ λ‚˜λ¨Έμ§€ 뢀뢄인 `(tagName: K, options?: ElementCreationOptions): HTMLElementTagNameMap[K]`λ₯Ό μ‚΄νŽ΄λ³΄κ² μŠ΅λ‹ˆλ‹€. 첫 번째 인수 `tagName`은 μ œλ„€λ¦­ λ§€κ°œλ³€μˆ˜ `K`둜 μ •μ˜λ©λ‹ˆλ‹€. TypeScript μΈν„°ν”„λ¦¬ν„°λŠ” 이 μΈμˆ˜λ‘œλΆ€ν„° μ œλ„€λ¦­ λ§€κ°œλ³€μˆ˜λ₯Ό _μΆ”λ‘ _ ν•  수 μžˆλŠ” μΆ©λΆ„ν•œ μ„±λŠ₯을 κ°€μ§€κ³  μžˆμŠ΅λ‹ˆλ‹€. μ΄λŠ” κ°œλ°œμžκ°€ λ©”μ„œλ“œλ₯Ό μ‚¬μš©ν•  λ•Œ μ‹€μ œλ‘œ μ œλ„€λ¦­ λ§€κ°œλ³€μˆ˜λ₯Ό μ§€μ •ν•  ν•„μš”κ°€ μ—†μŒμ„ μ˜λ―Έν•˜λ©°, μ–΄λ–€ 값이 `tagName`인수둜 μ „λ‹¬λ˜λ“  간에 `K`둜 μΆ”λ‘ λ˜λ―€λ‘œ μ •μ˜μ˜ λ‚˜λ¨Έμ§€ 뢀뢄에 μ‚¬μš©ν•  수 μžˆμ„ κ²ƒμž…λ‹ˆλ‹€. μ •ν™•νžˆ 무슨 일이 μΌμ–΄λ‚˜λŠ”μ§€λ₯Ό 보면 λ°˜ν™˜κ°’ `HTMLElementTagNameMap[K]`λŠ” `tagName`인수λ₯Ό κ°€μ§€κ³  ν•΄λ‹Ή νƒ€μž…μ„ λ°˜ν™˜ν•©λ‹ˆλ‹€. 이 μ •μ˜λŠ” μŠ€λ‹ˆνŽ« μ½”λ“œ `p` λ³€μˆ˜μ—μ„œ `HTMLParagraphElement`νƒ€μž…μ„ μ–»λŠ” λ°©λ²•μž…λ‹ˆλ‹€. 그리고 μ½”λ“œκ°€ `document.createElement('a')`μ˜€λ‹€λ©΄, `HTMLAnchorElement`νƒ€μž…μ˜ μš”μ†Œκ°€ λ©λ‹ˆλ‹€.
103103

104-
## The `Node` interface
104+
## `Node` μΈν„°νŽ˜μ΄μŠ€ (The `Node` interface)
105105

106-
The `document.getElementById` function returns an `HTMLElement`. `HTMLElement` interface extends the `Element` interface which extends the `Node` interface. This prototypal extension allows for all `HTMLElements` to utilize a subset of standard methods. In the code snippet, we use a property defined on the `Node` interface to append the new `p` element to the website.
106+
`document.getElementById` ν•¨μˆ˜λŠ” `HTMLElement`λ₯Ό λ°˜ν™˜ν•©λ‹ˆλ‹€. `HTMLElement` μΈν„°νŽ˜μ΄μŠ€λŠ” `Node` μΈν„°νŽ˜μ΄μŠ€λ₯Ό ν™•μž₯ν•œ `Element` μΈν„°νŽ˜μ΄μŠ€λ₯Ό ν™•μž₯ν•©λ‹ˆλ‹€. μ΄λŸ¬ν•œ ν”„λ‘œν† νƒ€μž… ν™•μž₯은 λͺ¨λ“  `HTMLElements`κ°€ ν‘œμ€€ λ©”μ„œλ“œμ˜ ν•˜μœ„ 집합을 ν™œμš©ν•  수 μžˆλ„λ‘ ν•©λ‹ˆλ‹€. μ½”λ“œ μŠ€λ‹ˆνŽ«μ—μ„œλŠ” `Node` μΈν„°νŽ˜μ΄μŠ€μ— μ •μ˜λœ 속성을 μ‚¬μš©ν•˜μ—¬ μ›Ή μ‚¬μ΄νŠΈμ— μƒˆ `p` μš”μ†Œλ₯Ό μΆ”κ°€ν•©λ‹ˆλ‹€.
107107

108108
### `Node.appendChild`
109109

110-
The last line of the code snippet is `app?.appendChild(p)`. The previous, `document.getElementById` , section detailed that the _optional chaining_ operator is used here because `app` can potentially be null at runtime. The `appendChild` method is defined by:
110+
μ½”λ“œ μŠ€λ‹ˆνŽ«μ˜ λ§ˆμ§€λ§‰ 쀄은 `app?.appendChild(p)`μž…λ‹ˆλ‹€. 이전 μ„Ήμ…˜(`document.getElementById`)μ—μ„œλŠ” `app`이 λŸ°νƒ€μž„μ— null일 κ°€λŠ₯성이 있기 λ•Œλ¬Έμ— _선택적 체이닝(optional chaining)_ μ—°μ‚°μžκ°€ 여기에 μ‚¬μš©λœλ‹€κ³  μ„€λͺ…ν–ˆμŠ΅λ‹ˆλ‹€. `appendChild`의 λ©”μ„œλ“œλŠ” λ‹€μŒκ³Ό κ°™μŠ΅λ‹ˆλ‹€:
111111

112112
```ts
113113
appendChild<T extends Node>(newChild: T): T;
114114
```
115115
116-
This method works similarly to the `createElement` method as the generic parameter `T` is inferred from the `newChild` argument. `T` is _constrained_ to another base interface `Node`.
116+
μ œλ„€λ¦­ λ§€κ°œλ³€μˆ˜ `T`κ°€ `newChild` μΈμˆ˜λ‘œλΆ€ν„° λ‚˜μ˜¨ 것이기 λ•Œλ¬Έμ— 이 λ©”μ„œλ“œλŠ” `createElement` λ©”μ„œλ“œμ™€ μœ μ‚¬ν•˜κ²Œ μž‘λ™ν•©λ‹ˆλ‹€. `T`λŠ” 또 λ‹€λ₯Έ κΈ°λ³Έ μΈν„°νŽ˜μ΄μŠ€μΈ `λ…Έλ“œ`둜 *μ œν•œ*λ©λ‹ˆλ‹€.
117117
118118
## `children`과 `childNodes`의 차이점 (Difference between `children` and `childNodes`)
119119

0 commit comments

Comments
Β (0)