반응형
inherit
-
자바스크립트 추상클래스 어떻게 작성할까요?자바스크립트 2023. 3. 12. 12:54
추상 클래스면 직접 생성이 불가능하고 추상메소드의 구현을 강제 해야 되잖아요? class Parent { constructor() { // 직접 생성하는거 못하게 할게요 if (this.constructor === Parent) { throw Error("This is abstract class"); } // 추상 메소드 구현하라고 강제할게요 if (this.abstractMethod === Parent.prototype.abstractMethod) { throw Error("you should implement abstract method"); } } abstractMethod() { throw Error("This is abstract method"); } } class Children extends..