Preserve ‘this’ reference in javascript prototype event handler [duplicate]

I find bind() being the cleanest solution so far:

this.bar.onclick = this.ClickEvent.bind(this);

BTW the other this is called that by convention very often.

Leave a Comment