I simulated a class in java script, 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?
Thanks for any help