here is an example Function constructor with implementing a class and you know JavaScript class is a syntactic sugar over the function structure.
classAnimal{constructor(name,energy){this.name=namethis.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}}constleo=newAnimal('Leo',7)
Nice article! You managed to make me understand generators for the first time XD.
By the way, could you please give me a practical use case of the Function consctructor? Thank you
here is an example Function constructor with implementing a
class
and you know JavaScriptclass
is a syntactic sugar over thefunction
structure.wanna know more, please check out this stackoverflow thread
Thanks!