js继承实现

function Car(Name,Age){
  this.Name = Name;
  this.Age = Age;
}
Car.prototype.showAge = function(){
   alert(this.Age);
}

function MoCar(Name,Age){
   Car.call(this,Name,Age);
}
MoCar.prototype = new Car();
MoCar.prototype.showName = function(){
   alert(this.Name);
}

var obj = new MoCar("jianboqi",12);
obj.showName();
obj.showAge();

 

你可能感兴趣的:(js)