Penguins, Properties, Prototype


#1

where I made a mistake?

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;
}
Penguin.prototype = Emperor();

// create an "emperor" object and print the number of legs it has
var emperor = new Emperor("name");

console.log(emperor.numLegs);

#2

@megawhiz46312,
You should use

Penguin.prototype = new Emperor();

J a v a S c r i p t and it's == p r o t o t y p e - C h a i n ==

They want you to set up the chain:

        OBJECT
  Object.prototype
           ^
           |
  Penguin.prototype  (( has the sayName Method))
           |                              ^
           |                              | 
           |                    Penguin Class-Constructor
           ^                   | with this constructor
           |                   |  you can create Instance's of Penguin
           |
           |    <<== You define this link in the Chain using
           ^            Emperor.prototype = new Penguin();
           |
  Emperor.prototype ((is empty))
           |               ^
           |               | 
           |          Emperor Class-constructor
           ^                   | with this constructor
           |                   |  you can create Instance's of Emperor
   /Instance /      <---   using new Emperor("aName");
   | of      |
   | Emperor |
    The Emperor-Instance has access
     to Penguin.prototype.sayName Method
     via the Emperor-prototype which is
      -chained- to the Penguin-prototype

#3

It should be here:

I guess you should be doing this.

Emperor.prototype = new Penguin();

#4

Thank you very much!)))


#5

You're welcome.

Have fun coding! :slight_smile:


#6

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();
console.log(emperor.numLegs);