在 javascript class 中使用 jQuery

Using jQuery in javascript class

function count(x,y) {
  this.x;
  this.y;
  this.plus = function() {
    return this.x + this.y;
  }
  this.checkResult = function() {
    $("#test").click(function() {
      this.plus(); //help here
    });
  }
}
<p id='test'></p>

"this" return 被点击的元素,那么如何在 jQuery 中使用 运行 方法?

试试这个:您可以将函数 this 存储到某个变量并使用它。

function count(x,y) {
  this.x;
  this.y;
  this.plus = function() {
    return this.x + this.y;
  }
  this.checkResult = function() {
    var $this = this;
    $("#test").click(function() {
      alert($this.plus()); //help here
    });
  }
}
<p id='test'>Click me</p>