If penguin inherits animal then what happens to numLegs = 2?


#1
// 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(); // inherits properties and methods from Animal.

if Penguin.prototype inherits all of Animals properties and methods than numLegs = 2 will become numLegs = undefined. are we still trying to keep numLegs = 2 for Penguin function or is the purpose to change it to undefined?


#2

Does your code work? Because I don't see any blatantly obvious coding errors, so I'm assuming you're good to go.

In terms of what happens to the "numLegs" in the "Penguin" class, that will override it's parent class when it give the parent class new parameters.

Essentially it's saying, "I'll inherit your traits" but because this is a child class think of it like a parent and a child in real life. No child is EXACTLY like either of their parents, and in this case that's true for "Penguin", saying penguin is an animal with 2 legs, but you could make a "Lion" class, and give it 4 legs instead, the parent just gives the skeleton to the child, and the child has their own values to the parents variables.