Skip to content

Instantly share code, notes, and snippets.

@Damimd10
Created March 24, 2019 18:18
Show Gist options
  • Save Damimd10/6fe2de1e2523c91e465c48ad406ed459 to your computer and use it in GitHub Desktop.
Save Damimd10/6fe2de1e2523c91e465c48ad406ed459 to your computer and use it in GitHub Desktop.
class Hero {
constructor(name) {
this.name = name
}
prepareForBattle(increaseCount) {
console.log(`I am ${this.name}! Let's go fighting!`)
increaseCount()
}
}
class Battle {
constructor(heroes) {
this.heroes = heroes
this.preparedHeroesCount = 0
this.heroes.forEach(heroe => {
heroe.prepareForBattle(this.increaseCount)
})
}
increaseCount() {
this.preparedHeroesCount++
console.log(`${this.preparedHeroesCount} heroes are now ready to fight!`)
}
}
const firstHero = new Hero('Flash')
const secondHero = new Hero('Thor')
new Battle([firstHero, secondHero])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment