add functional shorthands

This commit is contained in:
Azgaar 2022-05-17 22:34:14 +03:00
parent 159c1aa3e3
commit fc62143eae
5 changed files with 162 additions and 157 deletions

21
utils/shorthands.js Normal file
View file

@ -0,0 +1,21 @@
const query = document.querySelector.bind(document);
const queryAll = document.querySelectorAll.bind(document);
const byId = document.getElementById.bind(document);
const byClass = document.getElementsByClassName.bind(document);
const byTag = document.getElementsByTagName.bind(document);
Node.prototype.query = function (selector) {
return this.querySelector(selector);
};
Node.prototype.queryAll = function (selector) {
return this.querySelectorAll(selector);
};
Node.prototype.on = function (name, fn, options) {
this.addEventListener(name, fn, options);
};
Node.prototype.off = function (name, fn) {
this.removeEventListener(name, fn);
};