js练习题:构建函数创建一个车对象
该对象有重量,颜色,牌子,可以载人,拉货,耕田。
function Car (weight,color,brand){
this.weight = weight;
this.color = color;
this.brand = brand;
this.gongneng = function(manned,goods,ploughing){
console.log(manned + '\t' + goods + '\t' + ploughing);
}
}
var benzx = new Car('2吨','黑色','奔x');
console.log(benzx['weight']);
console.log(benzx.color);
console.log(benzx['brand']);
// for in 更简便
// for(k in benzx){
// console.log(benzx[k]);
// }
benzx.gongneng('载人' , '拉货' , '耕田');