instanceof1 [자바스크립트] 클래스의 상속과 instanceof 1. 클래스 상속 1.1 클래스 상속이란? 클래스 상속이란 다른 클래스의 속성과 메서드를 그대로 가져오는 것 즉 상속받는 것을 말한다. // 클래스 Animal class Animal { constructor(name, age) { this.name = name; this.age = age; } showName(){ console.log(`My name is ${this.name}`); } showAge(){ console.log(`I am ${this.age} years old`); } } // 클래스 Animal로 새로운 인스턴스인 pubao를 생성 let pubao = new Animal('pubao', 1, 'bamboo') // 클래스 Animal을 상속받은 클래스 Cat class Cat ex.. 2022. 3. 29. 이전 1 다음