re: Different type of functions in JavaScript VIEW POST

VIEW PARENT COMMENT VIEW FULL DISCUSSION

here is an example Function constructor with implementing a class and you know JavaScript class is a syntactic sugar over the function structure.


class Animal {
  constructor(name, energy) {
    this.name = name
    this.energy = energy
  }
  eat(amount) {
    console.log(`${this.name} is eating.`)
    this.energy += amount
  }
  sleep() {
    console.log(`${this.name} is sleeping.`)
    this.energy += length
  }
  play() {
    console.log(`${this.name} is playing.`)
    this.energy -= length
  }
}

const leo = new Animal('Leo', 7)

wanna know more, please check out this stackoverflow thread

Thanks!

code of conduct - report abuse