Co sądzicie?
const $ = sel => ({
els: typeof sel === 'string'
? [...document.querySelectorAll(sel)]
: sel.length
? [...sel]
: [sel],
each(call) {
this.els.forEach((el, i) => call(el, i));
return this;
},
on(type, listener) {
this.each((el, i) => el.addEventListener(type, listener.bind(this, el, i,)));
return this;
},
ready(call) {
this.on('DOMContentLoaded', call);
}
});
Bardzo prosta implementacja nowych funkcji np:
hide() {
this.each(el => el.style.display = 'none')
return this;
},
filter(condition) {
this.els = this.els.filter(condition)
return this;
}