Cannot Access Object's Methods From Within Event Handler Using `this`
Below is my code for FF Extension monitoring browsing behaviour. I can't access trim method from processClick method handling click event. Console shows this.trim is not a function
Solution 1:
Use this function
Function.prototype.bind = function(obj) {
var _method = this;
returnfunction() {
return _method.apply(obj, arguments);
};
}
Then,
this.registerListeners = function() {
this.doc.addEventListener("click", this.processClick.bind(this), false);
};
Post a Comment for "Cannot Access Object's Methods From Within Event Handler Using `this`"