18. Dry Penguins Strange Output - {}


#1



18. DRY Penguins


For some reason, the console outputs {} when I run my code below. It allows me to continue to the next lesson but I want to understand where the {} is coming from...

I tried refreshing the page and re-submitting the code


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

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

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


#2

Creates new, empty Animal.

{}

#3

I have a question.

Why the constructor of Penguin need to have a para called name?
Penguin inherit Animal which have had the property called name.
Can't Penguin reuse it?

Thanks cade