14. Prototype To The Rescue - Question



I just want to confirm, that in addition to using prototype in the below manner, we could also just add the bark method to the constructor, right? And all objects within the class would be able to use it.

function Dog (breed) {
  this.breed = breed;

// here we make buddy and teach him how to bark
var buddy = new Dog("golden Retriever");
Dog.prototype.bark = function() {

// here we make snoopy
var snoopy = new Dog("Beagle");
/// this time it works!


Are you implying to put it in the main object prototype?


Hey Bandit,

Yes, I believe so. If I created a constructor (ie. Person) and added a speak method to it then couldn't each person I created using the constructor use the speak method?



Hi Kevin,

Only if that Person constructor was the Parent or higher then the other constructor trying to inherit from it. :slight_smile:


This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.