I am trying to use classes based on Class.prototype in my project where I have no built-in functions. Given this example, it is not possible to remove the eventListener on the myVideo video myVideo that I have in my class.
This is a theoretical example, not the actual production code that I have.
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) {
Is there a way to leave the handler with the Class.prototype function and add and remove listeners. I need to create an instance and create many objects of this type, and I am afraid of memory leaks and persistence of the object (all previously created objects receive the "completed" event), leaving the anonymous functions not deleted as event handlers.
Or should I just consider a different approach (the built-in functions inside the initialize function, like event handlers). They really affect readability and consistency, so I want to avoid them at all costs.
source share