如何从JavaScript类中的原型函数调用事件处理程序中获取成员变量?

时间:2016-01-12 12:33:58

标签: javascript jquery class event-handling closures

我的问题简化为:

function ClassA(){
  this.x = 2;
}

ClassA.prototype = {
  init: function(){
    $(window).scroll(this.handleScroll);
  },
  handleScroll: function(){
    ... // how to get this.x, this is now referring to window and I cannot pass parameter from window.scroll
  }
}

0 个答案:

没有答案