function f(){
var a = Array.prototype.slice.call(arguments);//传的参数转为数组
var sum= 0;
a.forEach(function(item){
sum+=item*1;
})
return sum
}
console.log(f(1,2,3));//6
console.log(f(1,2,3,6));//12
//ES6可变数组
function ff(...a){
var sum = 0;
a.forEach(item=>{
sum+=item*1
})
return sum
}
console.log(ff(12,1,2));//15
console.log(ff(12,1,2,8));//23