Tuesday, 29 November 2016

jquery - How to get member variable in event handler called from a prototype function in a JavaScript class?

My problem is simplified to something like this:




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
}
}

No comments:

Post a Comment