자세한 내용은 아래 문서를 참고해주세요.
// __proto__ (비공식) 문법이에요. // prototype 공식입니다. // __proto__는 [[Prototype]]의 getter·setter // getter는? // setter는? class Human { constructor(name) { this.hp = 100; this.mp = 100; this.speed = 0; this.name = name; } attack(speed) { this.speed = speed; console.log(`${this.name}이 ${this.speed}의 속도로 공격합니다.`); } stop() { this.speed = 0; console.log(`${this.name}이 공격을 멈췄습니다.`); } } let 상점주인 = new Human("이호준"); let 대장장이 = new Human("홍길동"); class Hero extends Human{ skill() { console.log(`${this.name}가 스킬을 사용했습니다!`); } stop() { super.stop(); // 부모 클래스의 stop을 호출해 멈추고 this.skill(); // skill 사용 } } let 영웅 = new Hero("이호준"); 영웅.attack(5); 영웅.stop();