Black (and White) Penguin Magic


I was wondering - if the Penguin class is meant to 'inherit' the same elements as the Animal class, why do we need to input the 'name' and 'numLegs' into the Penguin class?

// 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) { = name,
    this.numLegs = 2

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

var penguin = new Penguin("Charlie");


I think this is coming in the next lessons...


Inheritance builds on the prototype. You can increase its complexity, but you can't decrease it.


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