在jQuery内部使用类的函数每个都存在于同一类的另一个函数中? [重复]

using this.p() inside jquery each() scope gives error. However it works perfectly out of each scope. So my problem is to avoid error inside each() scope.

class A() {
  x() {
    $("div.widget").each(function() {
      this.p(); //give error
    });
    this.p(); // print this (working)
  }

  p() {
    console.log("print this");
  }
}
评论