var arr = new Array(11,22,33,44,55);
var arr_ = new Array(21,44,32,36);
Array.prototype.sum = function() { //原型类似于 class样式 *类的原型加方法
// arr.sum =function(){ //类似于行间样式
var res = 0;
for (var i = 0; i < this.length; i++) {
// res=res+this[i];
res+=this[i];
}
return res;
}
alert(arr.sum());
alert(arr_.sum());
网友评论