let's get IT with DAVINA ๐ป
Module ๋ณธ๋ฌธ
Module
→ ์ฝ๋๋ฅผ ๊ทธ ํ์ผ ๋ด๋ถ์์๋ง ํ์ ํ ์ ์๋๋ก "๋ชจ๋ํ" ํ๋ ๊ฒ!
→ ๋ชจ๋ํ๋ฅผ ํ์ง ์์ผ๋ฉด ๊ธฐ๋ณธ์ ์ผ๋ก ๋ชจ๋ ํ์ผ์์ ์ฝ๋๋ฅผ ๊ณต์ ํด๋ฒ๋ฆด ์ ์๋ค. (์ด๋ฆ ์ ์ธ ์ถฉ๋์ด ์ผ์ด๋ ์ ์๊ฒ ์ฐ?!?!)
- ๋ธ๋ผ์ฐ์ ํ๊ฒฝ์์๋ window์,
- node ํ๊ฒฝ์์๋ global์ ์ ์ฅ๋์ด๋ฒ๋ฆฌ๊ธฐ ๋๋ฌธ!
//index.html
//๋ชจ๋ํํ๊ธฐ
<script type="module" src=""></script>
//module1.js
//export default๋ ํํ์ผ์์ ํ๋๋ง ๊ฐ๋ฅ!
export default function add(a,b){
return a+b;
}
//๊ทธ๋ฅ export
export function print() {
console.log("print");
}
//module2.js
import add from "./module1.js"
import {print} from "./module1.js"
//๋ค๋ฅธ ์ด๋ฆ์ผ๋ก ์ฐ๊ณ ์ถ์ด?
import {print as printMessage} from "./module1.js"
console.log(add(1,2)) //3
print(); //"print"
//๋ค๋ฅธ ์ด๋ฆ์ผ๋ก?
printMessage();
'DEV_IN > JavaScript' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[Inside JavaScript] Chapter 1. ์๋ฐ์คํฌ๋ฆฝํธ ๊ธฐ๋ณธ ๊ฐ์ (0) | 2023.03.27 |
---|---|
This (6) | 2023.02.28 |
Prototype (5) | 2023.02.28 |
JavaScript Event Loop๋? (4) | 2023.02.22 |
priceFormatter (0) | 2023.02.08 |
Comments