Skip to content

Commit

Permalink
resolve: conflict ν•΄κ²°
Browse files Browse the repository at this point in the history
  • Loading branch information
κ³ μ„Έμ’… committed Dec 18, 2023
1 parent 487886e commit 0ccd2f5
Showing 1 changed file with 0 additions and 35 deletions.
35 changes: 0 additions & 35 deletions docs/24_ν΄λ‘œμ €/κ³ μ„Έμ’….md
Original file line number Diff line number Diff line change
Expand Up @@ -90,38 +90,3 @@ const bar = foo();

이럴 경우 λŒ€λΆ€λΆ„μ˜ λΈŒλΌμš°μ €λŠ” μ΅œμ ν™”λ₯Ό 톡해 μƒμœ„ μŠ€μ½”ν”„μ˜ μ‹λ³„μž 쀑 ν΄λ‘œμ €κ°€ μ°Έμ‘°ν•˜κ³  μžˆλŠ” μ‹λ³„μžμΈ x만 κΈ°μ–΅ν•œλ‹€.<br>
μ—¬κΈ°μ„œ μ°Έμ‘°λ˜λŠ” μƒμœ„ μŠ€μ½”ν”„μ˜ λ³€μˆ˜ xλ₯Ό **자유 λ³€μˆ˜**라고 ν•œλ‹€.

### ν΄λ‘œμ €μ˜ ν™œμš©

ν΄λ‘œμ €λŠ” μƒνƒœλ₯Ό μ•ˆμ „ν•˜κ²Œ λ³€κ²½ν•˜κ³  μœ μ§€ν•˜κΈ° μœ„ν•΄ μ‚¬μš©ν•œλ‹€.<br>
즉, μƒνƒœλ₯Ό μ•ˆμ „ν•˜κ²Œ 은닉 ν•˜κ³  νŠΉμ • ν•¨μˆ˜μ—κ²Œλ§Œ μƒνƒœ 변경을 ν—ˆμš©ν•˜κΈ° μœ„ν•΄μ„œ μ‚¬μš©ν•œλ‹€.

```javascript
const increase = (function () {
let num = 0;

return function () {
return ++num;
};
})();

console.log(increase()); //1
console.log(increase()); //2
console.log(increase()); //3
```

μœ„ μ˜ˆμ œμ—μ„œ λ³Ό 수 μžˆλ“―μ΄ ν΄λ‘œμ €λŠ” `num`을 μ§€μ—­λ³€μˆ˜λ‘œ μ‚¬μš©ν•΄ μƒνƒœκ°€ μ˜λ„μΉ˜ μ•Šκ²Œ λ³€κ²½λ˜μ§€ μ•Šλ„λ‘ μ•ˆμ „ν•˜κ²Œ μ€λ‹‰ν•˜κ³ , νŠΉμ • ν•¨μˆ˜μ—κ²Œλ§Œ μƒνƒœ 변경을 ν—ˆμš©ν•˜μ—¬ μƒνƒœλ₯Ό μ•ˆμ „ν•˜κ²Œ λ³€κ²½ν•˜κ³  μœ μ§€ν•˜κΈ° μœ„ν•΄ μ‚¬μš©λœλ‹€.

μ—¬κΈ°μ„œ μƒνƒœκ°€ μ˜λ„μΉ˜ μ•Šκ²Œ λ³€κ²½λ˜μ§€ μ•Šλ„λ‘ μ•ˆμ „ν•˜κ²Œ μ€λ‹‰ν•œλ‹€λŠ” 것은 **μΊ‘μŠν™”**λΌλŠ” μš©μ–΄λ‘œ λŒ€μ²΄ν•  수 μžˆλ‹€.<br>
μΊ‘μŠν™”λž€ 객체의 μƒνƒœλ₯Ό λ‚˜νƒ€λ‚΄λŠ” ν”„λ‘œνΌν‹°μ™€ ν”„λ‘œνΌν‹°λ₯Ό μ°Έμ‘°ν•˜κ³  μ‘°μž‘ν•  수 μžˆλŠ” λ™μž‘μΈ λ©”μ„œλ“œλ₯Ό ν•˜λ‚˜λ‘œ λ¬ΆλŠ” 것을 λ§ν•œλ‹€.

ν΄λ‘œμ €λ₯Ό μ΄μš©ν•΄ μΊ‘μŠν™”μ™€ 정보은닉을 λΉ„μŠ·ν•˜κ²Œ 흉내낼 수 μžˆμ§€λ§Œ μžλ°”μŠ€ν¬λ¦½νŠΈμ˜ ν•œκ³„λ‘œμΈν•΄ μ™„μ „ν•œ μΊ‘μŠν™”λ₯Ό μ§„ν–‰ν•˜κΈ°λž€ μ–΄λ ΅λ‹€.

> ν˜„μž¬λŠ” ν΄λž˜μŠ€μ™€ `private`κ°€ μ œκ³΅λœλ‹€.
`var`ν‚€μ›Œλ“œλ₯Ό μ‚¬μš©ν•œλ‹€λ©΄ μ˜ˆμƒμΉ˜ λͺ»ν•œ μ‹€ν–‰ κ²°κ³Όκ°€ λ°œμƒν•  수 μžˆλ‹€. λ”°λΌμ„œ λ˜λ„λ‘ `let, const` ν‚€μ›Œλ“œλ₯Ό μ‚¬μš©ν•˜μž.<br>
κ·Έ μ΄μœ λŠ” `var`ν‚€μ›Œλ“œλ₯Ό μ‚¬μš©ν•΄ μ„ μ–Έλœ λ³€μˆ˜λ“€μ€ 블둝 레벨 μŠ€μ½”ν”„κ°€ μ•„λ‹Œ ν•¨μˆ˜λ ˆλ²¨ μŠ€μ½”ν”„λ₯Ό κ°–κΈ° λ•Œλ¬Έμ— μ „μ—­ λ³€μˆ˜κ°€ λœλ‹€.

ν•˜μ§€λ§Œ `let, const` ν‚€μ›Œλ“œλ₯Ό μ‚¬μš©ν•΄ μ„ μ–Έλœ λ³€μˆ˜λ“€μ€ 맀번 블둝 레벨 μŠ€μ½”ν”„λ₯Ό μƒμ„±ν•˜λ©°, 블둝을 반볡 μ‹€ν–‰ν•  λ•Œλ§ˆλ‹€ μƒˆλ‘œμš΄ λ ‰μ‹œμ»¬ ν™˜κ²½μ„ 생성해, 반볡 λ‹Ήμ‹œμ˜ μƒνƒœλ₯Ό μŠ€λƒ…μˆμ„ μ°λŠ” κ²ƒμ²˜λŸΌ μ €μž₯ν•œλ‹€.

μΆ”κ°€λ‘œ 이보닀 κΉ”λ”ν•œ λ°©λ²•μœΌλ‘œλŠ” κ³ μ°¨ν•¨μˆ˜λ“€μ„ μ‚¬μš©ν•˜λŠ” 방법이 μžˆλ‹€.

0 comments on commit 0ccd2f5

Please sign in to comment.