20.Penguins Emperor inherit from Penguin?


#1

Why cannot Emperor inherit from Penguin if the inherit code is inside the Emperor class? It works if the code is outside the Emperor class, but not inside.
Is it possible to inherit from inside the Emperor, or is the only way to put it outside?

undefined
Oops, try again. Make sure to log the number of legs emperor has!


function Penguin(name) {
    this.name = name;
    this.numLegs = 2;
}

// create your Emperor class here and make it inherit from Penguin
function Emperor(name) {
    this.name = name;
// Does not work    Emperor.prototype = new Penguin();
}
// Does work        Emperor.prototype = new Penguin();


#2

prototype extends an object after its defined, so only outside is possible

this answe discusses this in insane much detail, if you have the time, read it


#3

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