I'm trying to extend the Node.addEventListener
method so I can do some events management like:
Node.prototype.on = function (type, listener, useCapture) {
'use strict';
var i, evt;
this.events = this.events || [];
for (i = 0; i < this.events.length; i += 1) {
evt = this.events[i];
if (this === evt[0] && type === evt[1]) {
this.removeEventListener(type, evt[2], evt[3]);
this.events.splice(i, 1);
}
}
this.events.push([this, type, listener, useCapture]);
return this.addEventListener(type, listener, useCapture);
};
But in this case, instead of naming it on
I would like to name it the same addEventListener
so I can guarantee any javascript will work on it.
So the point here is that if I name the function as addEventListener
instead on on the return clause it will cause an endless loop. so I was thinking if is there any way to make it call the super
method instead?
Thanks in advance