25.8.1 클래스 상속과 생성자 함수 상속

상속에 의한 클래스 확장

상속에 의한 클래스 확장

class Animal {
  constructor(age, weigth){
    this.age = age;
    this.weigth = weigth;
  }

  eat() { return 'eat'; }

  move() { return 'move'; }
}

// Bird 클래스 - 상속을 통해 Animal 클래스를 확장함
class Bird **extends** Animal {
  fly() { return 'fly'; }
}

const bird = new Bird(1,5);

console.log(bird); //Bird { age: 1, weigth: 5 }
console.log(bird instanceof Bird); //true
console.log(bird instanceof Animal); //true

console.log(bird.eat()); //eat
console.log(bird.move()); //move
console.log(bird.fly()); //fly

상속에 의해 확장된 클래스 Bird에 의해 생성된 인스턴스의 프로토타입 체인

상속에 의해 확장된 클래스 Bird에 의해 생성된 인스턴스의 프로토타입 체인

25.8.2 extends 키워드

// 부모 클래스
class Base {}

// 자식 클래스(=파생/서브 클래스)
class Derived extends Base {}

extends

extends 키워드

extends 키워드