原型

function Car(carbrand,model){
  this.carbrand=carbrand;
  this.model=model;
}
Car.prototype.Acce=function(){
  console.log('this is '+this.carbrand+'---'+this.model)
}
Car.prototype.hoot=function(){
  console.log('嘟嘟嘟。。')
 }
Car.prototype.lun=4;

var car =new Car('aa','bb');
car.hoot();
car.Acce();
function Tesla(carbrand,model,power){
  Car.call(this,carbrand,model);
   this.power=power;
}
Tesla.prototype=Object.create(Car.prototype);
console.log(Tesla.prototype.constructor)
Tesla.prototype.constructor=Tesla;
console.log(Tesla.prototype.constructor)
Tesla.prototype.Power=function(){
console.log(this.power);
}
var tes=new Tesla('tes','car','dian');

tes.hoot();
tes.Acce();
Tesla.prototype.Acce=function(){
console.log('this is testla');
}
tes.Acce();
tes.Power();

console.log(car.lun);
console.log(tes.lun)
console.log(typeof Tesla)

  结果

 

posted @ 2016-10-11 13:39  kangjie-kin  阅读(177)  评论(0编辑  收藏  举报