javascript中各类的prototype属性

时间:2014-11-04 01:30:54   收藏:0   阅读:151

prototype

作用:获取调用对象的对象原型引用

应用:可以为某对象原型添加方法

例:

function getMax()
{
    var max = this[0];
    for(var x=0; x<this.length; x++)
    {
         if(this[x] > max)
             max = this[x];
     }
     return max;
}    
Array.prototype.getMax = getMax;

//以后数组使用获取最大值的方法就可以如下调用,例如arr是以个整数数组
arr.getMax();//OK

 

评论(0
© 2014 mamicode.com 版权所有 京ICP备13008772号-2  联系我们:gaon5@hotmail.com
迷上了代码!