Prototype animal/penguin


Its not behaving incorrectly. I just have a question. Can someone explain to me in detail how the computer is thinking step by step when penguin.sayName(); is called. I just want to understand so I can write my own code without guessing what the computer is thinking. Thank You in advance.

R//prototype animal/penguin

function Animal (name, numLegs){ = name;
	this.numLegs = numLegs;
Animal.prototype.sayName = function(){
	console.log("Hi my name is " +;
function Penguin (name){ = name;
	this.numLegs = 2
Penguin.prototype = new Animal();
var penguin = new Penguin("Frank");


we have two objects:

animal and penguin

penguin is an animal, so it inherits from Animal.

then we create an instance, a penguin called frank:

var penguin = new Penguin("Frank");

now we can call a method:


sayName is a animal method, but given Penguin inherits from Animal, we can also call parent classes methods


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