//create new method Number.prototype.toHexString=function(){ return this.toString(16); }; var iNum=15; alert(iNum.toHexString());//f Array.prototype.equeue=function(vItem){ return this.push(vItem); }; var aColor=["red","green"]; aColor.equeue("blue"); alert(aColor);//red,green,blue Array.prototype.dequeue=function(){ return this.shift(); }; aColor.dequeue(); alert(aColor);//green,blue Array.prototype.indexof=function(vItem){ for(i=0;i<this.length;i++){ if(vItem==this[i]){ return i; } } return -1; } var oColor=["red","green","blue"]; alert(oColor.indexof("blue"));//2 Object.prototype.showValue=function(){ alert(this.valueOf()); }; var sString="green"; var iNum=23; sString.showValue();//green iNum.showValue();//23 //函数名只是指向函数的指针,因此可以修改该指针指向的函数。重定义已有的方法。 //re definite method Function.prototype.toString=function(){ alert("function code hidden!"); }; function sayHi(){ alert("Hi"); } sayHi.toString();//function code hidden! Function.prototype.originaltoString=Function.prototype.toString; Function.prototype.toString=function(){ if(this.originaltoString().length>=100){ alert("Function too long to display"); } alert(this.originaltoString()); };