1

I have a question about declaring methods for a function in JavaScript. Suppose that I declare a function Monster in these two following ways: First way:

function Monster() {
  this.growl = () => {
    console.log('grrr!');
  }
}

Second Way:

function Monster() {
}
Monster.prototype.growl = () => {
  console.log('grrr!');
}

The question is: when I instantiate n monster I do create n methods for both way of declaration or I create only one method for all the monsters I instantiated?

Giovanni
  • 53
  • 1
  • 7

0 Answers0