Beesbeesbees

이동국·2022년 9월 25일

Beesbeesbees

Beesbeesbees는 페어분과 함께 진행하였다.
위의 class structure은 상속이 이루어졌기 때문에, Grub을 기반으로 한 Bee들은 부모의 속성을 사용할 수 있다.

Grub

class Grub {

  constructor(){
    this.age = 0;
    this.color = 'pink';
    this.food ='jelly';
  }
  eat(){
    return 'Mmmmmmmmm jelly';
  }
}

module.exports = Grub;

Bee

const Grub = require('./Grub');

class Bee extends Grub {
  constructor(){
    super();
    this.age = 5;
    this.color = 'yellow';
    this.job = 'Keep on growing';
  }
 
}

module.exports = Bee;

HoneyMakerBee

const Bee = require('./Bee');

class HoneyMakerBee extends Bee {
  constructor(){
    super();
    this.age = 10;
    this.job = 'make honey';
    this.honeyPot = 0;
  }
  makeHoney(){
    this.honeyPot +=1
  }
  giveHoney(){
    this.honeyPot -=1
  }

}

module.exports = HoneyMakerBee;

ForagerBee

const Bee = require('./Bee');

class ForagerBee extends Bee {
  constructor(){
    super();
    this.age = 10;
    this.job = 'find pollen';
    this.canFly = true;
    this.treasureChest = [];
  }
  forage(item){
    this.treasureChest.push(item);
  }

}

module.exports = ForagerBee;

0개의 댓글