Skip to content

Instantly share code, notes, and snippets.

@dented
Created February 22, 2018 04:31
Show Gist options
  • Save dented/008ba8b9035e12a6827941ce0b450257 to your computer and use it in GitHub Desktop.
Save dented/008ba8b9035e12a6827941ce0b450257 to your computer and use it in GitHub Desktop.
Bling Event Delegation
Node.prototype.on = window.on = function (name, delegate, fn) {
if(arguments.length !== 3) {
return this.addEventListener(name, arguments[1]);
}
return this.addEventListener(name, function (e) {
if(e.target.matches(delegate)){
return fn.apply(e.target, arguments);
}
})
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment