1.普通求和
function sum(){ var result=0; for(var i=0;i<arguments.length;i++){ result+=arguments[i]; } return resulat; } alert(sum(2,5));
2.面向对象
var arr=[2,5]; Array.prototype.sum=function(){ var result=0; for(var i=0;i<this.length;i++){ result+=this[i] } return resulat; }; alert(arr.sum());