I'm playing around with a micro library for use within projects and I'm having difficulty adding a method to a function.
In this case I have shorthanded document.querySelector()
which is all good and works as needed. However I have no real idea how to add a method to that which inherits the element from the selector function.
This is similar to how jquery works but a lot of code examples online are a fair few years old. I'm wanting a modern solution and to understand how this works going forward. I really hope someone can educate me and help to get this to work.
Cheers!
let S = (selector, container = document) => {
return container.querySelector(selector);
};
S.prototype = {
classAdd: (_class) => this.classList.add(_class)
};
S('div').classAdd('red');