Why does assigning to `this.prototype` within the constructor not set the prototype of the newly-created object?
18:24 29 Mar 2015

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 + "
"); document.write(aDog.color + "
" + aDog.woof() + "
" + 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.

javascript prototype