1. 사전 참고할 자료
constructor - JavaScript | MDN
constructor 메서드는 클래스의 인스턴스 객체를 생성하고 초기화하는 특별한 메서드입니다.
developer.mozilla.org
extends - JavaScript | MDN
extends 키워드는 클래스를 다른 클래스의 자식으로 만들기 위해 class 선언 또는 class 식에 사용됩니다.
developer.mozilla.org
super - JavaScript | MDN
super 키워드는 부모 오브젝트의 함수를 호출할 때 사용됩니다.
developer.mozilla.org
vscode에서 터미널 여는 법
2. 문제 풀이
Bee class functionality
✓ `age` 속성은 `5`이어야 합니다
✓ `color` 속성은 `yellow`이어야 합니다
✓ `food` 속성은 Grub으로부터 상속받습니다
✓ `eat` 메소드는 Grub으로부터 상속받습니다
✓ `job` 속성은 `Keep on growing`이어야 합니다
const Grub = require('./Grub');
class Bee extends Grub{
// TODO..
// TODO..npn
constructor() {
super();
this.age = 5;
this.color = 'yellow';
this.job = 'Keep on growing';
}
}
module.exports = Bee;
ForagerBee class functionality
✓ `age` 속성은 `10`이어야 합니다
✓ `job` 속성은 `find pollen`이어야 합니다
✓ `color` 속성은 `Bee`로부터 상속받습니다
✓ `food` 속성은 `Grub`으로부터 상속받습니다
✓ `eat` 메소드는 `Grub`으로부터 상속받습니다
✓ `canFly` 속성은 `true`이어야 합니다
✓ `treasureChest` 속성은 빈 배열 `[]`이어야 합니다
✓ `forage` 메소드를 통해 `treasureChest` 속성에 보물을 추가할 수 있어야 합니다
const Bee = require('./Bee');
class ForagerBee extends Bee{
// TODO..
constructor() {
super();
this.age = 10;
this.job = 'find pollen';
this.canFly = true;
this.treasureChest = [];
}
forage(treasure) {
this.treasureChest.push(treasure);
}
}
module.exports = ForagerBee;
Grub class functionality
✓ `age` 속성은 `0`이어야 합니다
✓ `color` 속성은 `pink`이어야 합니다
✓ `food` 속성은 `jelly`이어야 합니다
✓ `eat` 메소드가 존재해야 합니다
✓ `eat` 메소드를 통해 `Grub`이 젤리를 먹습니다
class Grub {
// TODO..npn
constructor() {
this.age = 0;
this.color = 'pink';
this.food = 'jelly';
}
eat() {
return 'Mmmmmmmmm jelly';
}
}
module.exports = Grub;
HoneyMakerBee class functionality
✓ `age` 속성은 `10`이어야 합니다
✓ `job` 속성은 `make honey`이어야 합니다
✓ `color` 속성은 `Bee`로부터 상속받습니다
✓ `food` 속성은 `Grub`으로부터 상속받습니다
✓ `eat` 메소드는 `Grub`으로부터 상속받습니다
✓ `honeyPot` 속성은 `0`이어야 합니다
✓ `makeHoney` 메소드는 `honeyPot`에 1씩 추가합니다
✓ `giveHoney` 메소드는 `honeyPot`에 1씩 뺍니다
const Bee = require('./Bee');
class HoneyMakerBee extends Bee{
// TODO..
constructor() {
super();
this.age = 10;
this.job = 'make honey';
this.honeyPot = 0;
}
makeHoney(){
this.honeyPot++;
}
giveHoney(){
this.honeyPot--;
}
}
module.exports = HoneyMakerBee;
'프로그래밍 > 프로젝트' 카테고리의 다른 글
번들링과 웹팩(web-pack) (0) | 2022.07.25 |
---|---|
구글 클론 코딩 (0) | 2022.07.24 |
[Backend] 인증/보안 auth-basic-cookie (0) | 2022.07.15 |
StatesAirline Client part1 (0) | 2022.06.14 |
React Twittler SPA (0) | 2022.06.03 |
댓글