So i'm trying to setup prototypal inheritance using the surrogate method and I have run into a behavior that seems weird for me. Here are my classes:
function Animal(name) {
this.name = name;
}
Animal.prototype.eat = function() {
console.log("mmm... food...")
};
function Dog(name) {
this.name = name
};
var Surrogate = function() {}
Surrogate.prototype = Animal.prototype;
Now, I want to setup Animal as the base class. If I make an instance of Surrogate:
The browser console says that s is an instance of Surrogate.
However, when I set Dog class's prototype to the instance of Surrogate:
It becomes an instance of Animal? Why is this happening? Is this correct or am I interpreting it wrong?