-
Notifications
You must be signed in to change notification settings - Fork 42
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1267 from Ryan-Dia/ryan-dia
48μ₯ λͺ¨λ - κ°μ² μ
- Loading branch information
Showing
1 changed file
with
41 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
**TIL(Today I learn) κΈ°λ‘μΌ** : 2024. 01. 24 | ||
|
||
# 48. λͺ¨λ | ||
|
||
## 1. λͺ¨λμ μΌλ°μ μλ―Έ | ||
|
||
λͺ¨λμ΄λ μ ν리μΌμ΄μ μ ꡬμ±νλ κ°λ³μ μμλ‘ μ¬μ¬μ© κ°λ₯ν μ½λ μ‘°κ°μ λ§ν©λλ€. | ||
λͺ¨λμ΄ μ±λ¦½νλ €λ©΄ λͺ¨λμ μμ λ§μ νμΌ **μ€μ½ν(λͺ¨λ μ€μ½ν)**λ₯Ό κ°μ§ μ μμ΄μΌ ν©λλ€. | ||
|
||
>μμ λ§μ νμΌ μ€μ½νλ₯Ό κ°λ λͺ¨λμ μμ°9λͺ¨λμ ν¬ν¨λμ΄ μλ λ³μ, ν¨μ, κ°μ²΄ λ±)μ κΈ°λ³Έμ μΌλ‘ λΉκ³΅κ° μνμ λλ€. | ||
>μ½κ²λ§ν΄ μμ λ§μ νμΌ μ€μ½νλ₯Ό κ°λ λͺ¨λμ λͺ¨λ μμ°μ μΊ‘μνλμ΄ λ€λ₯Έ λͺ¨λμμ μ κ·Όν μ μμ΅λλ€. | ||
- λͺ¨λμ 곡κ°κ° νμν μμ°μ νμ νμ¬ λͺ μμ μΌλ‘ μ νμ 곡κ°κ° κ°λ₯νκ³ μ΄λ₯Ό `export`λΌ ν©λλ€. | ||
- λͺ¨λ μ¬μ©μλ λͺ¨λμ΄ κ³΅κ°ν μμ° μ€ μΌλΆ λλ μ 체λ₯Ό μ νν΄ μμ μ μ€μ½ν λ΄λ‘ λΆλ¬λ€μ¬ μ¬μ¬μ©ν μ μκ³ μ΄λ₯Ό `import`λΌκ³ ν©λλ€. | ||
|
||
![image](https://github.com/Ryan-Dia/Javascript-Deep-Dive-Study/assets/76567238/f94f4b6b-972f-44c0-aaea-8d83bd463f22) | ||
|
||
## 2. μλ°μ€ν¬λ¦½νΈμ λͺ¨λ | ||
|
||
μλ°μ€ν¬λ¦½νΈ λ°νμ νκ²½μΈ `Node.js`λ λͺ¨λ μμ€ν μ μ¬μ€μ νμ€μΈ `CommonJS`λ₯Ό μ±ννκ³ λ μμ μΈ μ§νλ₯Ό κ±°μ³ κΈ°λ³Έμ μΌλ‘λ `CommonJS`μ¬μμ λ°λ₯΄κ³ μμ΅λλ€. λ°λΌμ `Node.js` νκ²½μμλ νμΌλ³λ‘ λ 립μ μΈ νμΌ μ€μ½ν(λͺ¨λ μ€μ½ν)λ₯Ό κ°μ΅λλ€. | ||
|
||
|
||
## 3. ES6 λͺ¨λ(ESM) | ||
|
||
ES6μμλ ν΄λΌμ΄μΈνΈ μ¬μ΄νΈ μλ°μ€ν¬λ¦½νΈμμ λμνλ λͺ¨λ κΈ°λ₯μ μΆκ°νμ΅λλ€. | ||
|
||
### 1) λͺ¨λ μ€μ½ν | ||
|
||
- ESMμ λ μμ μΈ λͺ¨λ μ€μ½νλ₯Ό κ°μ΅λλ€. | ||
- ESMμ΄ μλ μΌλ°μ μΈ μλ°μ€ν¬λ¦½νΈ νμΌμ script νκ·Έλ‘ λΆλ¦¬ν΄μ λ‘λν΄λ λ μμ μΈ λͺ¨λ μ€μ½νλ₯Ό κ°μ§ μμ΅λλ€. | ||
|
||
### 2) export ν€μλ | ||
|
||
- λͺ¨λ λ΄λΆμμ μ μΈν μλ³μλ₯Ό μΈλΆμ 곡κ°νμ¬ λ€λ₯Έ λͺ¨λμ΄ μ¬μ¬μ©ν μ μκ² νλ €λ©΄ `export`ν€μλλ₯Ό μ¬μ©ν΄μΌν©λλ€. | ||
- export ν€μλλ μ μΈλ¬Έ μμ μ¬μ©ν©λλ€. μ΄λ¬μ¨ λ³μ, ν¨μ, ν΄λμ€ λ± λͺ¨λ μλ³μλ₯Ό `export`ν μ μμ΅λλ€. | ||
|
||
### 3) import ν€μλ | ||
|
||
- λ€λ₯Έ λͺ¨λμμ 곡κ°ν μλ³μλ₯Ό μμ μ λͺ¨λ μ€μ½ν λ΄λΆλ‘ λ‘λνλ €λ©΄ `import`ν€μλλ₯Ό μ¬μ©ν©λλ€. | ||
- λ€λ₯Έ λͺ¨λμ΄ `export`ν μλ³μ μ΄λ¦μΌλ‘ `import`ν΄μΌ νλ©° `ESM`μ κ²½μ° νμΌ νμ₯μλ₯Ό μλ΅ν μ μμ΅λλ€. | ||
|