title: Removing event listeners as Class.prototype functions
body: <p>I'm trying to have a Class.prototype based classes in my project, where I don't have inline functions. Considering this example, it's impossible to remove the eventListener on <code>myVideo</code> video object, that I have in my class.</p>
  
  <p><em>This is a theoretical example, not an actual production code I have.</em></p>
  
  <pre><code>var myClass = function () {
      this.initialize();
  }
  
  MyClass.prototype.myVideo = null;
  
  MyClass.prototype.initialize = function () {
      this.myVideo = document.getElementById("myVideo");
      this.myVideo.addEventListener("ended", this.onMyVideoEnded, false);
      this.myVideo.play();
  }
  
  MyClass.prototype.onMyVideoEnded = function (event) {
      // cannot remove event listener here
      // this.myVideo.removeEventListener("ended", this.onMyVideoEnded, false);
  }
  </code></pre>
  
  <p>Is there a way to leave the handler as a Class.prototype function and add and remove listeners. I need to instantiate and create a lot of objects of this sort, and am afraid of memory leaks, and object persistancy (all of previously created objects receive the "ended" event) when leaving anonymous functions not removed as event handlers.</p>
  
  <p>Or should I just consider a different approach (inline functions, inside the initialize function, as event handlers). These really impact readability and consistency, so I want to avoid them on all costs.</p>