I simulated a class in JavaScript; it's code is here:
function myclass()
{
this.count ;
this.init = function(){
$("div.mybtn").click({n:this},function(e){
e.data.n.count++;
});
}
this.getCount = function(){
alert(this.count);
}
}
Then I created an instance of this class and executed it's method init(), but when I click on any div.mybtn element, it did not increment the value of this.count.
It seems the object this was passed to event handler by value not by reference.
How I can pass a variable to an event handler by reference?