2 ms·
You might be interested in bling.js: https://gist.github.com/paulirish/12fb951a8b893a454b32 https://gist.github.com/paulirish/12fb951a8b893a454b32 I was simila
by theandrewbailey 6y ago
You might be interested in bling.js: https://gist.github.com/paulirish/12fb951a8b893a454b32 https://gist.github.com/paulirish/12fb951a8b893a454b32
I was similarly inspired:
if (undefined === window.$) {
window.$ = document.querySelectorAll.bind(document);
[EventTarget.prototype, window, XMLHttpRequest.prototype].forEach(function setOnOff(p) {
Object.defineProperty(p, "on", {
get() {
return function onElement(t, f) {
this.addEventListener(t, f);
return this;
};
}
})
Object.defineProperty(p, "off", {
get() {
return function offElement(t, f) {
this.removeEventListener(t, f);
return this;
};
}
});
});
[NodeList.prototype, HTMLCollection.prototype].forEach(function setOnArray(p) {
Object.setPrototypeOf(p, Array.prototype);
Object.defineProperty(p, "on", {
get() {
return function onArray(t, f) {
this.forEach(function onEach(e) {
e.addEventListener(t, f);
});
return this;
};
}
});
Object.defineProperty(p, "off", {
get() {
return function offArray(t, f) {
this.forEach(function offEach(e) {
e.removeEventListener(t, f);
});
return this;
};
}
});
});
}