20. Penguins, Properties, and the Prototype (Question on inheritance)


So this answer works but I had a question why I had to have " this.name = name; " in the Emperor class for this to work?

I thought since Emperor was inheriting from the Penguin class, I wouldnt have to declare anything. Wouldnt Emporer pull all the properties?

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;
Emperor.prototype = new Penguin();
// create an "emperor" object and print the number of legs it has
var emperor = new Emperor("Mike");


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