Skip to content

Instantly share code, notes, and snippets.

@jtmthf
Created April 14, 2020 15:08
Show Gist options
  • Select an option

  • Save jtmthf/3b740623b2dcdd2417a88f6af769d18b to your computer and use it in GitHub Desktop.

Select an option

Save jtmthf/3b740623b2dcdd2417a88f6af769d18b to your computer and use it in GitHub Desktop.
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