Penguin Black Magic


// the original Animal class and sayName method
function Animal(name, numLegs) { = name;
    this.numLegs = numLegs;
Animal.prototype.sayName = function() {
    console.log("Hi my name is " +;

// define a Penguin class
function Penguin(name, numLegs){ = name;
  this.numLegs = numLegs;

// set its prototype to be a new instance of Animal
Penguin.prototype = new Animal();
var Penguin = new Penguin("Jimmy");
Penguin.sayName( );

not sure whats wrong with this can someone please advise?


We must use a separate variable that is not the same as the name of the class. Even penguin will work, since it is a different case.


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