zoukankan      html  css  js  c++  java
  • 原型

    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)
    

      结果

  • 相关阅读:
    简化单例模式
    static
    单例模式之懒汉模式
    Car race game
    poj-2403
    poj-2612
    poj-1833
    poj--2782
    poj--2608
    poj--3086
  • 原文地址:https://www.cnblogs.com/kin-jie/p/5948964.html
Copyright © 2011-2022 走看看