JavaScript封装一个对象

function Car(sColor,iDoors,iMpg) {
  this.color = sColor;
  this.doors = iDoors;
  this.mpg = iMpg;
  this.drivers = new Array("Mike","John");
  this.test=function(){
    console.log("test");
  }
}

Car.prototype.showColor = function() {
  alert(this.color);
};
var objCar = new Car("red", 1, 2);

猜你喜欢

转载自blog.csdn.net/y7u8t6/article/details/83376680
今日推荐