Skip to content

Instantly share code, notes, and snippets.

@zazaulola
Created June 14, 2024 14:31
Show Gist options
  • Save zazaulola/3b909c0fcaf774a30c7907b1fad520d7 to your computer and use it in GitHub Desktop.
Save zazaulola/3b909c0fcaf774a30c7907b1fad520d7 to your computer and use it in GitHub Desktop.
Object.defineProperties(EventTarget.prototype, {
on: { value: EventTarget.prototype.addEventListener },
off: { value: EventTarget.prototype.removeEventListener },
emit: {
value: function (eventType, eventData) {
let event = new Event(eventType);
if (eventData) {
Object.assign(event, eventData, { details: eventData });
}
this.dispatchEvent(event);
}
}
});
Object.defineProperties(Element.prototype, {
$: { value: Element.prototype.querySelector },
$$: { value: Element.prototype.querySelectorAll },
});
Object.defineProperties(Document.prototype, {
$: { value: Document.prototype.querySelector },
$$: { value: Document.prototype.querySelectorAll },
});
Object.defineProperties(globalThis, {
$: { value: s => document.querySelector(s) },
$$: { value: s => document.querySelectorAll(s) },
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment