码迷,mamicode.com
首页 > 编程语言 > 详细

javascript中各类的prototype属性

时间:2014-11-04 01:30:54      阅读:151      评论:0      收藏:0      [点我收藏+]

标签:style   blog   io   color   ar   使用   java   for   sp   

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

 

javascript中各类的prototype属性

标签:style   blog   io   color   ar   使用   java   for   sp   

原文地址:http://www.cnblogs.com/fantasy01/p/4072581.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!