I'm facing a challenge with TypeScript Classes where I constantly need to use Function.bind() to link HTML Element events to the current instance.
class VideoAdProgressTracker extends EventDispatcher
{
private _video:HTMLVideoElement;
constructor(video:HTMLVideoElement)
{
super();
this._video = video;
this._video.addEventListener("timeupdate", this.handleTimeUpdateEvent);
}
private handleTimeUpdateEvent(event)
{
// Something
}
}
It gets messy having to save the bound anonymous function repeatedly, especially when dealing with multiple events. I wish there was a simpler way to keep it bound without all the extra steps.
Any ideas for simplifying this process?