title: removeEventListener on anonymous functions in JavaScript
body: <p>I have an object that has methods in it. These methods are put into the object inside an anonymous function. It looks like this:</p>
  
  <pre><code>var t = {};
  window.document.addEventListener("keydown", function(e) {
      t.scroll = function(x, y) {
          window.scrollBy(x, y);
      };
      t.scrollTo = function(x, y) {
          window.scrollTo(x, y);
      };
  });  
  </code></pre>
  
  <p>(there is a lot more code, but this is enough to show the problem)</p>
  
  <p>Now I want to stop the event listener in some cases. Therefore I am trying to do a removeEventListener but I can't figure out how to do this. I have read in other questions that it is not possible to call removeEventListener on anonymous functions, but is this also the case in this situation?</p>
  
  <p>I have a method in t created inside the anonymous function and therefore I thought it was possible. Looks like this:</p>
  
  <pre><code>t.disable = function() {
      window.document.removeEventListener("keydown", this, false);
  }
  </code></pre>
  
  <p>Why can't I do this?</p>
  
  <p>Is there any other (good) way to do this?</p>
  
  <p>Bonus info; this only has to work in Safari, hence the missing IE support.</p>