title: Javascript: problem with "this"-keyword with event listeners
body: <p>I have a problem with eventlisteners  in javascript that is probably due to my incomplete control of the language.</p>
  
  <p>I wish to register event listeners using addEventListener() / attachEvent(); I also want to be able to remove the listeners later on, so I can't register anonymous functions. </p>
  
  <p>Say I now want to register a method of an object as an event listener. First I'd expected <code>addEventListener(event, node, object.method)</code> to work. However, after reading up on events I now understand that the <code>this</code> keyword will refer to the event target when the event listener is called, not my object. </p>
  
  <p>To work around this, I have created a new method, methodCallback of the object, like so:</p>
  
  <pre><code>object.methodCallback = function () {
      self.method(); 
  }
  </code></pre>
  
  <p>the <code>self</code> variable is set to copy <code>this</code> in the object constructor.  I then register object.methodCallback as an eventlistener. </p>
  
  <p>I feel this must be the wrong way to do it. But what is the right way?</p>
  
  <p>I apologize if this question is common, but I haven't been able to find an answer on SO so far</p>