“this” keyword in event methods when using JavaScript prototype object

You need:

this.link.onclick = this.EventMethod.bind(this);

…’bind’ is part of Prototype, and returns a function which calls your method with ‘this’ set correctly.

Leave a Comment