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

c++ - Does curly brackets matter for empty constructor?

Those brackets declare an empty, inline constructor. In that case, with them, the constructor does exist, it merely does nothing more than t...