Skip to content

Instantly share code, notes, and snippets.

@minmaxdata
Created August 14, 2018 21:58
Show Gist options
  • Save minmaxdata/156020e2e844933b35688bbb1e72c7e9 to your computer and use it in GitHub Desktop.
Save minmaxdata/156020e2e844933b35688bbb1e72c7e9 to your computer and use it in GitHub Desktop.
class keyword created by minmaxdata - https://repl.it/@minmaxdata/class-keyword
class Animal {
constructor(name, energy) {
this.name = name
this.energy = energy
}
eat(amount) {
console.log(`${this.name} is eating.`)
this.energy += amount
}
sleep(length) {
console.log(`${this.name} is sleeping.`)
this.energy += length
}
play(length) {
console.log(`${this.name} is playing.`)
this.energy -= length
}
}
const leo = new Animal('Leo', 7)
const snoop = new Animal('Snoop', 10)
leo.eat(10)
snoop.play(5)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment