Created
April 14, 2020 15:08
-
-
Save jtmthf/3b740623b2dcdd2417a88f6af769d18b to your computer and use it in GitHub Desktop.
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
| export const $ = document.querySelector.bind(document); | |
| export const $$ = document.querySelectorAll.bind(document); | |
| Node.prototype.on = window.on = function (name: string, fn: EventListenerOrEventListenerObject) { | |
| this.addEventListener(name, fn); | |
| }; | |
| (NodeList.prototype as any).__proto__ = Array.prototype; | |
| NodeList.prototype.on = NodeList.prototype.addEventListener = function (name, fn) { | |
| this.forEach((elem) => { | |
| elem.on(name, fn); | |
| }); | |
| }; | |
| declare global { | |
| interface Window { | |
| on: Window['addEventListener'] | |
| } | |
| interface Node { | |
| on: Node['addEventListener'] | |
| } | |
| interface NodeList extends Array<Node> { | |
| addEventListener: Node['addEventListener']; | |
| on: Node['addEventListener']; | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment