export방식에 따라 lazy가 될 수도 있고, static 될 수 있음.
lazy : import 후 사용 호출 시점
static : import 후 export된 항목이 하나라도 [사용 선언] 된 경우
(사용선언? : 클릭 이벤트 함수에 코드작성만 하고 이벤트로 인해 호출 하지 아니함.)
class Life {
constructor(msg: string) {
console.log("created Life Class", msg);
}
}
const otherExport = "string";
export { otherExport };
export { Life };
const LifeInstance = new Life("in file");
export { LifeInstance };
import { Life, LifeInstance, otherExport } from "@/composables/test";
...
...
onClickExportTest(event: Event) {
/* 직접 사용하고자 하는 클래스(LifeInstance)가 아닌
다른 변수(otherExport)를 사용선언만 해도 LifeInstance 생성자 호출 */
console.log(otherExport);
// result : created Life Class in file(static)
new Life("from other") // 실제 사용 시 호출
// result : created Life Class From other
},
create Life class in file(static) // import 후 사용선언 한 경우
created Life Class from other // 사용 선언 후 실제로 호출이 일어날 경우.