728x90
super, extends이용하기 ★★★
Grub.js
class Grub {
constructor(){
this.age= 0;
this.color= 'pink';
this.food= 'jelly';
}
eat(){
return 'Mmmmmmmmm jelly' ;
}
}
module.exports = Grub;
bee.js
const Grub = require('./Grub');
class Bee extends Grub{
constructor(){ //Grub에 food랑 eat있어서 따로 안써도된다.
super();
this.age= 5;
this.color= 'yellow';
this.job= `Keep on growing`;
}
}
module.exports = Bee;
HoneyMakerBee.js
const Bee = require('./Bee');
class HoneyMakerBee extends Bee{
constructor(){
super();
this.age= 10;
this.job= `make honey`;
this.honeyPot= 0;
}
makeHoney(){
this.honeyPot++;
}
giveHoney(){
this.honeyPot--;
}
}
module.exports = HoneyMakerBee;
ForagerBee.js
const Bee = require('./Bee');
class ForagerBee extends Bee{
constructor(){
super();
this.age= 10;
this.job= `find pollen`;
this.canFly= true;
this.treasureChest= [];
}
forage(treasure){
this.treasureChest.push(treasure);
}
}
module.exports = ForagerBee;
728x90
'과제기록' 카테고리의 다른 글
[페어]statesairline-server (0) | 2023.02.08 |
---|---|
[페어] statesairline-client (0) | 2023.02.03 |
[project] 나만의 아고라스테이츠만들기 (0) | 2023.01.10 |