스프린트/beesbeesbees

beesbeesbees

테오구 2021. 11. 3. 15:29
728x90

상속에 관한 문제인 것 같다.

 

Grub.js: Grub은 다른 모든 Bee의 기반이 됩니다.

더보기

class Grub {

// TODO..

constructor(age, color, food) {

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 {

// TODO..

constructor() {

super() // 부모의 constructor를 받아옵니다.

this.age = 5 // 부모의 constructor를 업데이트 해줍니다.

this.color = 'yellow'

this.job = 'Keep on growing'

}

}

 

module.exports = Bee

ForagerBee.js

더보기

const Bee = require('./Bee')

 

class ForagerBee extends Bee {

// TODO..

constructor() {

super()

this.age = 10

this.job = 'find pollen'

this.canFly = true

this.treasureChest = [] //새로운 constructor를 가져올 수 있습니다.

}

// `forage` 메소드를 통해 `treasureChest` 속성에 보물을 추가함

forage(treasure) {

this.treasureChest.push(treasure)

}

}

 

module.exports = ForagerBee

 

HoneyMakerBee.js

 

더보기

const Bee = require('./Bee')

 

class HoneyMakerBee extends Bee {

// TODO..

constructor() {

super()

this.age = 10

this.job = 'make honey'

this.honeyPot = 0

}

//  `makeHoney` 메소드는 `honeyPot`에 1씩 추가합니다

makeHoney() {

this.honeyPot++

}

//  `giveHoney` 메소드는 `honeyPot`에 1씩 뺍니다

giveHoney() {

this.honeyPot--

}

}

 

module.exports = HoneyMakerBee

728x90