Last active
March 27, 2021 19:10
-
-
Save WebReflection/13a3682240c83d2a657d2882e56d1bc6 to your computer and use it in GitHub Desktop.
The smallest, cross browser, DOM chainable `.on()` shortcut for `addEventListener`
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(function (F, I, X, DOM, on) { | |
DOM = (F.Node || F.Element).prototype; | |
on = F.Object.defineProperty || | |
function (t, k, d) { | |
t[k] = d.value; | |
}; | |
I in F || on(F, I, X); | |
I in DOM || on(DOM, I, X); | |
I in F.document || on(F.document, I, X); | |
}( | |
window, | |
'on', | |
{ | |
writable: true, | |
configurable: true, | |
value: function on() { | |
this.addEventListener.apply(this, arguments); | |
return this; | |
} | |
} | |
)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Sorry couldn't resist when you support
on
withoutun
😄Compressed (Closure compiler):