Prototype

类似CSS中class,一次给一组对象添加一个方法。

Array.prototype.sum=function()
{
  var result=0;
  for(var i=0;i<this.length;i++)    
 {
    result+=this[i];
 }
    return result;
}    

 

posted @ 2020-05-04 09:29  孝文  阅读(105)  评论(0编辑  收藏  举报