복습 챌린지
Coddy JavaScript 여정의 객체 지향 프로그래밍 섹션에 포함된 레슨 — 56개 중 29번째.
챌린지
상속을 사용하여 가구 클래스 만들기
작업 1: Chair 클래스 만들기Furniture를 상속받는 Chair 클래스를 만드세요:
- 생성자(constructor)에서
super()를 사용하여 부모 클래스로부터material과color를 상속받으세요. - 속성 추가:
numberOfLegs - 메서드 추가:
"Sitting on the chair"를 반환하는sit()
작업 2: Table 클래스 만들기Furniture를 상속받는 Table 클래스를 만드세요:
- 생성자(constructor)에서
super()를 사용하여 부모 클래스로부터material과color를 상속받으세요. - 속성 추가:
shape - 메서드 추가:
"Item placed on table"를 반환하는placeItem()
직접 해보기
import { Furniture } from './furniture.js';
import { Table } from './table.js';
import { Chair } from './chair.js';
// 테스트 코드 - 수정하지 마세요
const myChair = new Chair("wood", "brown", 4);
console.log(myChair.describe()); // "brown wood furniture"가 출력되어야 함
console.log(myChair.numberOfLegs); // 4가 출력되어야 함
console.log(myChair.sit()); // "Sitting on the chair"가 출력되어야 함
const myTable = new Table("glass", "clear", "round");
console.log(myTable.describe()); // "clear glass furniture"가 출력되어야 함
console.log(myTable.shape); // "round"가 출력되어야 함
console.log(myTable.placeItem()); // "Item placed on table"가 출력되어야 함