e.g.:
function myclass (htmlelement) {
this.element = htmlelement;
}
myclass.prototype.hoverfunc = function() {
alert (this.element.id);
}
myclass.prototype.doListen = function() {
this.element.addEventListener ('mouseover', function() {this.hoverfunc();}.bind(this),false);
}
elListen = new myclass (document.getElementById('foo'));
elListen.doListen();
How would I create a method that would remove the listener from the element?
Why would you want to keep the anonymous function?
Also, be careful with
addEventListener()/removeEventListener()since they are DOM Level 2 standards based – something IE doesn’t do.