과제기록
[페어] beesbeesbees
뭉지야
2023. 1. 28. 17:23
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