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