javascript - How can i create nested functions -
i'm trying create "nested functions". can't seem find solution!
const func1 = (value1) => { const func2 = (value2) => { console.log(value1 + value2) } } func1(2).func2(3)
what want accomplish create own little "jquery function"
const $ = (element) => { const addclass = (name) => { const x = document.queryselectorall(element); (i = 0; < x.length; i++) { x[i].classname = name } } } $('#circle').addclass('nice')
i think topic broad single question, here simple example of how this, started:
const $ = (selector) => { const items = document.queryselectorall(selector); const self = { addclass: (name) => { (let = 0; < items.length; i++) { items[i].classlist.add(name); } return self; }, removeclass: (name) => { (let = 0; < items.length; i++) { items[i].classlist.remove(name); } return self; } }; return self; } $('#circle').addclass('nice').removeclass('bad');
.nice { color: green; } .bad { color: red; } .fancy { text-decoration: underline; }
<div id='circle' class='bad fancy'> hello </div>
Comments
Post a Comment