How does 'this' work in JavaScript?

后端 未结 4 1460
长情又很酷
长情又很酷 2020-12-21 04:31

I know there are several other posts on this topic but they still leave me confused.

I\'ve included jQuery and everything and, I have a simple javascript class like

4条回答
  •  北海茫月
    2020-12-21 05:33

    
    function CarConstructor(){
      var _this = this;  
      this.speed=19; // in mph
      this.make="Ford";
      this.fillKph = function (){
          $("#kphdiv").html(_this.speed*1.61);
      };
    }
    
    car1 = new CarConstructor();
    car1.fillKph();
    

提交回复
热议问题