Nov 24, 2008

Dyamically adding function to how hierarchy

We can add functionality to whole hierarchy by changing the prototype, for example.


  function Animal() {
      var r = {};   
      return r;
  }

 var a = new Animal();

 Object.prototype.greet = function() {
     alert("hello");
 };  

 a.greet();