Can you think of a variant of the below that preservese.currentTarget?
function _on(eventName, elementSelector, handler, el = document) { //e.currentTarget is document when the handler is called
el.addEventListener(eventName, function(e) {
// loop parent nodes from the target to the delegation node
for (var target = e.target; target && target != this; target = target.parentNode) {
if (target.matches(elementSelector)) {
handler(target, e);
break;
}
}
}, false);
}
It is important to note, that e.currentTarget is not available as usual. (I had to patch that)
Sources of research so far:
Can you think of a variant of the below that preserves
e.currentTarget
?It is important to note, that
e.currentTarget
is not available as usual. (I had to patch that)I also substituted
handler.call(target, e)
with
handler(target, e)