re: Different type of functions in JavaScript VIEW POST


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 JavaScript class is a syntactic sugar over the function structure.

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

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

wanna know more, please check out this stackoverflow thread


code of conduct - report abuse