프로토타입 상속과 프로토타입 체인
Chapter 17 - Prototype Inheritance and Prototype Chain
프로토타입 체인
프로토타입 상속
class Life {
constructor(live) {
this.live = live;
}
}
class Human extends Life {
constructor(live, name) {
super(live);
this.name = name;
}
}
프로토타입 체인으로 지정된 대상 객체의 모든 멤버를 상속받을 수 있다. __proto__
등을 직접 사용하여 연결하는 방식 등 매우 지저분하였으나 ES6 이후로 class
문법이 공식 지원되면서 다른 언어들처럼 extends
와 super
키워드 등을 통하여 깔끔하게 작성할 수 있게 되었다.
초판: 2024. 08. 19. 10:41:43
© 2024 이 문서는 "CC BY 4.0 국제규약" 라이선스로 배포 되었습니다. 모든 권리는 저자에게 있습니다.