Removing event listeners as Class.prototype functions
You need to bind your function onMyVideoEnded
with context where you attached it:
For example:
this.myVideoEndedHandler = this.onMyVideoEnded.bind(this);
this.myVideo.addEventListener("ended", this.myVideoEndedHandler, false);
To remove listener also use stored handler:
this.myVideo.removeEventListener("ended", this.myVideoEndedHandler, false);
This is because when event triggers your function onMyVideoEnded
gets wrong this
argument.
i use this:
this.element.handler = handler.bind(this);
this.element.removeEventListener('event', this.element.handler, false);
this.element.addEventListener('event', this.element.handler, false);
or use a WeakMap object:
var handlers = new WeakMap();
var self = this;
handlers.set(this.element, { handler: handler.bind(self) });
var handler = handlers.get(this.element).handler;
this.element.removeEventListener('event', handler, false);
this.element.addEventListener('event', handler, false);