title: How to use removeEventListener when event handler is a prototype function?
body: <p>This is a follow-up to this <a href="https://stackoverflow.com/questions/26159405/why-is-this-not-equal-to-object-and-why-is-property-undefined">question</a>. The problem is that my call to <code>removeEventListener</code> does not work. What do I have to change below so that it does work?</p>
  
  <p>My custom object:</p>
  
  <pre><code>//Custom Editor Example with event listeners
  var CE = function (id) {
      'use strict';
  
      // assume not a valid object
      this.isValid = false;
      this.element = document.getElementById(id);
      if (this.element !== null) {
          this.id = id;
          this.init();
          this.isValid = true;
      }
  };
  
  
  CE.prototype.addEvent = function (event, callback, caller) {
      'use strict';
  
      // check for modern browsers first
      if (typeof window.addEventListener === 'function') {
          return caller.element.addEventListener(event, function (e) {callback.call(caller, e); }, false);
      }
      // then for older versions of IE
      return this.element.attachEvent('on' + event, function (e) {callback.call(caller, window.event); });
  };
  
  CE.prototype.init = function () {
      'use strict';
      this.addEvent('keydown', this.onCustomKeyDown, this);
      // add other event listeners
  };
  </code></pre>
  
  <p>This is how I'm trying to remove the event handler:</p>
  
  <pre><code>CE.prototype.removeEvent = function (event, callback, caller) {
      'use strict';
      caller.element.removeEventListener(event, callback, false);
  };
  
  
  CE.prototype.destroy = function () {
      'use strict';
      this.removeEvent('keydown', this.onCustomKeyDown, this);
      // remove other event listeners
  };
  </code></pre>
  
  <p>And this is the signature of the prototype function that handles the event.</p>
  
  <pre><code>CE.prototype.onCustomKeyDown = function onCustomKeyDown(e) {
  </code></pre>
  
  <p>If I understand correctly, removeEventListener cannot be used to remove event handlers which are anonymous functions. Is that the issue here? Do I need to change the way I'm calling <code>addEventListener</code>?</p>