title: Addressing a Object-Function in an JavaScript Event-Handler
body: <p>let's say I have a JavaScript-Class like this:</p>
  
  <pre><code>Foo.prototype = {
    init: function() {
      $(document).keydown(function(event) {
        this.onKeyDown(event);
      });
    }
  
    onKeyDown: function(event) {
      alert("bar");
    }
  }
  
  myObj = new Foo();
  myObj.init();
  </code></pre>
  
  <p>This Code won't work, because in</p>
  
  <pre><code>$(document).keydown(function(event) {
      this.onKeyDown(event);
  });
  </code></pre>
  
  <p>the 'this' is of course unknown and doesn't address the object. How can i address the onkeydown-method of the Foo-Class anyhow?</p>
  
  <p>I don't want exchange 'this' with 'myObj' (the name of the Object) since i may want to use the class for other Objects aswell.</p>
  
  <p>Thanks for your help!</p>