Mega Code Archive

 
Categories / JavaScript Tutorial / Object Oriented
 

Add method to Object class

Since all objects used in JavaScript are inherited from Object, all of the object can use the method added to Object. Object.prototype.showValue = function () {     alert(this.valueOf()); }; var str = "hello"; var iNum = 25; str.showValue(); iNum.showValue();