There is a constructor:

var Human = function(name){ this.name = name; }; 

I will write down the new method in the prototype of the constructor:

 Human.prototype.say = function(what){ console.log(this.name + " : " + what) }; 

Now every object created using the new keyword will inherit a Human.prototype, like this:

 var alex = new Human("Alex"); 

Is this the only way to add new methods to the constructor?

  • 2
    What does it mean to add new methods to the constructor ? - Grundy
  • and where does inheritance come from? - ampawd 7:49 pm
  • one
    There is also a functional style link - Andrew B

0