prototype是在IE4及其以后版本引入的一个针对于某一类的对象的方法,而且特殊的地方便在于:它是一个给类的对象添加方法的方法!在实际编程中所用到的肯定不只是已有方法的增强,更多的实行的功能的要求。
例子:(1)Number.add(num):作用,数字相加
实现方法:Number.prototype.add=function(num){return(this+num);}
检验:alert((3).add(15))--->18
例子:(2)Array.push(new_element)作用:在数组末尾加入一个新的元素
实现方法:
Array.prototype.push=function(new_element){
this[this.length]=new_element;
returnthis.length;
}