객체 간 상속을 구현하는 메커니즘
.__proto__
과.prototype
을 통해 접근할 수 있다.function Car(brand, model, color) { this.brand = brand; this.model = model; this.color = color; this.speed = 0; this.accelerate = function() { this.speed += 10; }; this.brake = function() { this.speed -= 10; }; } function Airplane(brand, model, color) { Car.call(this, brand, model, color); // 상위 객체 Car의 생성자 호출 } Airplane.prototype = Object.create(Car.prototype);
class Car { constructor(brand, model, color) { this.brand = brand; this.model = model; this.color = color; this.speed = 0; } accelerate() { this.speed += 10; } brake() { this.speed -= 10; } } class Airplane extends Car { // Airplane에 Car크클래스를 상속 constructor(brand, model, color) { super(brand, model, color) // 상위 클래스의 brand, model, color을 가져온다. } }