How can I return __plugin inside add and css function without return __plugin inside them. Can I use a higher order function? Everything is working as expected but I would like to know and maybe refactor this code.
I don't want to write return __plugin every time only one time.
const $ = (el) => {
let _plugin = {};
const element = document.querySelector.bind(document);
const css = (style) => {
Object.assign(element(el).style, style)
return _plugin;
}
const add = (c) => {
element(el).classList.add(c)
return _plugin;
}
_plugin = { add, css }
return _plugin
}
Thank you.
__pluginand you don't want to return__plugin?return __pluginevery time . I just want to know if there is a better way.$function returns an object with add and css methods. The OP wants to be able to chain function calls, e.g.$('#foo').add(className).css({backgroundColor: 'red'});