export(내보내기)
export
// 배열 내보내기
export let num = [1,2,3,4,5]
// 상수 내본개ㅣ
export const a=3
// 클래스 내보내기
export class User{
constructor(name){
this.name=name;
}
}
default export
; export할 때 이름을 따로 명시하지 않아도 됨 but 1개의 함수만 내보내기 가능
export default function (){
console.log(1)
}
import(가져오기)
// main.js 파일. B대신 B'라는 이름 사용
import {A, B as B'} from './main.js
// main.js 파일. c.js파일의 모든 함수 가져옴
import * as A from './main.js
// main.js 파일로부터 default export한 것을 가져옴. 이름은 내 마음대로 정해도 됨
import A' from './main.js
Reference
https://ko.javascript.info/import-export
모듈 내보내고 가져오기
ko.javascript.info
'WebProgramming > JS' 카테고리의 다른 글
[TS] TS의 타입 시스템? & Compliation Context (0) | 2022.06.12 |
---|---|
[TS] TypeSCript이란? & 타입 (0) | 2022.06.12 |
[JS] JSON (0) | 2022.06.11 |
[JS] 정규표현식 (0) | 2022.06.11 |
[JS] 구조 분해(Destructuring), 전개 연산자(...)(spread, rest) (0) | 2022.06.11 |
[JS] 원시 데이터, 참조형 데이터 / 얕은 복사와 깊은 복사 (0) | 2022.06.11 |
[JS] 메소드(String, Math, Array, Object) (0) | 2022.06.10 |
[JS] 생성자 함수(Prototype), Class 상속 (0) | 2022.06.06 |