I'm figuring out prototypes in JS, and I can't figure for the life of me why this doesn't work:
var Mammal = {
legs: 4
}
function Dog(color, soundItMakes) {
this.prototype = Mammal;
this.color = color;
this.soundItMakes = soundItMakes;
this.woof = function() { return this.soundItMakes; }
}
aDog = new Dog("brown", "beep beep!");
document.write(Mammal.legs + "<br>");
document.write(aDog.color + "<br>" + aDog.woof() + "<br>" + aDog.legs);
The first document.write()
returns 4 as would be expected, but the second returns undefined for aDog.legs. Any advice would be a huge help.