From what I read, in JS, the prototype refers to the Object that its constructor functions refer to.
So, let's say,
function Dog(name){
this.name = name;
}
Dog.prototype.bark = function(){alert("Woof");}
That means now, the Dog's prototype has a bark
property.
var dog = new Dog("Doggo");
dog.bark();
Works fine and alerts Woof
However, when I add,
function Cat(name){
this.name = name;
}
var cat = new Cat("Little kitten");
cat.bark(); //Nothing happens, why?
Both Dog and Cat's prototype point to the same Object.prototype for now (kinda like how Object class is the superclass of all created classes in JAVA, I know prototypes and classes aren't the same but the structure is similar).
So when I am modifying Dog's prototype by adding the bark
property, it should reflect in Cat as well because they point to the same Object.prototype which is getting modified? What is wrong with my understanding?