如何在var auto
没有明确方式的情况下调用每个对象?
我的意思是不必将它们中的每一个都写在函数调用、speedAverage
函数和return
计算平均值中。
function Car (model, speed) {
this.model = model;
this.speed = speed;
}
var speedAverage = function(car1, car2, car3) {
return (car1.speed + car2.speed + car3.speed)/ veh.length;
};
var auto = [
new Car("BMW", 220),
new Car("Ford", 260),
new Car("DeLorean", 350)
];
console.log("The average between these cars is " + speedAverage(auto[0], auto[1],
auto[2]));
谢谢。