title: How to get the current object reference in a class method?
body: <p>Usually I develop on Java, and now I am studying JavaScript/HTML5 Canvas things. And I get a strange situation from Java developer's point of view.</p>
  
  <p>There's a html5 canvas object on the html page, and I want to track the mouse click events on this canvas.</p>
  
  <p>I declared class <code>GameBoard</code> and initialized its properties:</p>
  
  <pre><code>function GameBoard() {
    // defining a property for GameBoard class instance
    this.myProperty = 'some text here';
  
    // getting canvas element
    this.boardCanvas = document.getElementById("myCanvas");
  
    // setting the mouse click event listener
    this.boardCanvas.addEventListener("mousedown", this.handleMouseClick, false);
  }
  </code></pre>
  
  <p>and there's a class method to handle mouse click events:</p>
  
  <pre><code>GameBoard.prototype.handleMouseClick = function(event) {
  
       alert(this.myProperty);
  
  }
  </code></pre>
  
  <p><code>handleMouseClick()</code> will display <code>undefined</code> because <code>this</code> in <code>handleMouseClick()</code> method refers to the HTML5 Canvas instance (boardCanvas).</p>
  
  <p>My question: how can I refer the current <code>GameBoard</code> class instance inside of <code>handleMouseClick</code> method to get <code>myProperty</code> field value defined in the class constructor?</p>
  
  <p>What I am doing wrong here?</p>
  
  <p>Thank you.</p>