프로그래밍/Js

변수로 클래스 인스턴스 생성할때

소행성왕자 2023. 6. 12. 11:53

함수에서 인자를 받아 클래스를 생성해야 합니다.

이럴때 사용하는 방법입니다.

/*
type : Retim, Retim6, RetimS
*/

aa(type) {
	
    const Cls = eval(`this.${type}`);
    const retim6 = new Cls();
    retim6.manage();

}