=>
function (...args) {
this.elements.forEach(elem =>
fn(...args, elem));
return this;
};
const features = {
on: elementHandler((eventName, handler, element) =>
element.addEventListener(eventName, handler))
};
global.$ = selector =>
Object.create(features, {
elements: {
value: document.querySelectorAll(selector)
}
});
})(typeof window !== 'undefined' ? window : this)
I would probably flip the argument order tbh: const each = fn => function (...args) { this.elements.forEach(elem => fn(elem, ...args)); return this; };
Обсуждают сегодня