> For the complete documentation index, see [llms.txt](https://april.gitbook.io/learning-js/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://april.gitbook.io/learning-js/chapter-9./9.2/9.2.5.md).

# 9.2.5 상속

* 클래스의 인스턴스는 클래스의 기능을 모두 상속
* 객체의 프로토타입에서 메서드를 찾지 못하면? 자바스크립트는 프로토타입의 프로토타입을 검색 **(프로토타입 체인 생성)**
  * 자바스크립트는 조건에 맞는 프로토타입을 찾을 때까지 프로토타입 에니을 계속 거슬러 올라감
  * 찾지 못하는 경우 에러를 발생시킴

**=> 클래스의 계층 구조를 만들 때 프로토타입 체인을 염두해 두면 더욱 효율적인 구조를 만들 수 있음**

### **extends 키워드**

* 어떤 클래스의 서브클래스로 만들어줌

#### super()

* 슈퍼클래스의 생성자를 호출하는 특별한 함수
* 서브클래스에서는 이 함수를 반드시 호출해야함 (호출하지 않으면 에러 발생)

```javascript
  class Car extends Vehicle {
    constructor() {
      super();
      console.log("Car created");
    }

    deployAirbags() {
      console.log("BWOOSH!");
    }
  }

  const v = new Vehicle();
  v.addPassenger("Frank");
  v.addPassenger("Judy");

  console.log(v.passengers); // ["Frank", "Judy"]

  const c = new Car();
  c.addPassenger("Alice");
  c.addPassenger("Cameron");

  console.log(c.passengers); // ["Alice", "Cameron"]

  v.deployAirbags(); // Uncaught TypeError: v.deployAirbags is not a function
  c.deployAirbags();
```
