Skip to content

Instantly share code, notes, and snippets.

@theScottyJam
Created October 25, 2021 13:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save theScottyJam/4d502807fca1ab7ce9ebf69d7599a05f to your computer and use it in GitHub Desktop.
Save theScottyJam/4d502807fca1ab7ce9ebf69d7599a05f to your computer and use it in GitHub Desktop.
Article: Composition Alone Can't Replace Inheritance - public helpers
// Public helpers
export const monsterBehaviors = {
kill(monster) {
userInventory.add(monster.dropLoot())
removeFromUi(this)
}
}
// private helpers
const monsterHelpers = {
attack() {
playHurtAnimation()
}
}
export class Slime { ... }
export class Skeleton { ... }
export class Clown {
dropLoot() {
return [new Key()]
}
attack() {
monsterHelpers.attack()
if (itsTime()) {
showCutScene()
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment