6週目/Beesbeesbeesbees


パクリの継承概念を応用したスプレーです.

ファイル全体がそうです.まずGribファイルを作成します.
プロパティはthisで宣言します.メソッドはコンストラクション関数を宣言するだけです.

1. Grub

class Grub {
  constructor(){
  this.age = 0;
  this.color = 'pink'
  this.food = 'jelly'
  }

  eat(){
    return 'Mmmmmmmmm ' + this.food
  }
}

module.exports = Grub;

2. Bee


extendsとsuperを使用してGRUBを継承し、残りのエンクロージャを追加
const Grub = require('./Grub');

class Bee extends Grub{
  // TODO..
  constructor(){
    super();

    this.age = 5;
    this.color = 'yellow';
    this.job = 'Keep on growing';
  }

}

module.exports = Bee;

3. HoneyMakerBee

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

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

4. ForagerBee

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

class ForagerBee extends Bee{
  constructor(){
    super()

    this.age = 10;
    this.job = 'find pollen';
    this.canFly = true;
    this.treasureChest = [];
  }
  forage(e){
    return this.treasureChest.push(e)
  }
}
最初はどうやって手を出すかは難しいかもしれませんが、繰り返すと簡単です.