6週目/Beesbeesbeesbees
パクリの継承概念を応用したスプレーです.
ファイル全体がそうです.まずGribファイルを作成します.
プロパティはthisで宣言します.メソッドはコンストラクション関数を宣言するだけです.
extendsとsuperを使用してGRUBを継承し、残りのエンクロージャを追加
ファイル全体がそうです.まず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)
}
}
最初はどうやって手を出すかは難しいかもしれませんが、繰り返すと簡単です.Reference
この問題について(6週目/Beesbeesbeesbees), 我々は、より多くの情報をここで見つけました https://velog.io/@support/코드스테이츠-6주차-Beesbeesbeesテキストは自由に共有またはコピーできます。ただし、このドキュメントのURLは参考URLとして残しておいてください。
Collection and Share based on the CC Protocol