main.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
// 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();
var penguin = new Penguin("jack");
penguin.sayName();
Native Browser JavaScript