class를 이용해서 객체를 생성하는 경우, 자바스크립트에서도 자바에서와 마찬가지로 상속도 구현해줄 수 있다. 그 예시는 다음과 같다.
class Rectangle {
constructor(w, h){
this.width = w;
this.height = h;
}
getArea(){
return this.width * this.height;
}
}
class Square extends Rectangle{
constructor(length){
super(length, length);
}
}
let square = new Square(10);
console.log(square.getArea());