Add method to Object class : Object : Object Oriented JAVASCRIPT TUTORIALS


JAVASCRIPT TUTORIALS » Object Oriented » Object »

 

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();







HTML code for linking to this page:

Follow Navioo On Twitter

JAVASCRIPT TUTORIALS

 Navioo Object Oriented
» Object