4 ms·
Post E6 I personally think that Javascript is good enough to raw dog. Producing code that isn't locked to a single framework or library is its own reward.
by 1GZ0 2y ago
Post E6 I personally think that Javascript is good enough to raw dog.
Producing code that isn't locked to a single framework or library is its own reward.
- Zekio 2y agoespecially since most jquery usage I've seen in the past couple can be replaced with a shortened reference to document.querySelectorAll
- 1GZ0 2y agoYeah, thats a common criticism of ES6 selector I see a lot. They are so damn verbose.
- lioeters 2y agoNot only verbose, querySelectorAll returns a NodeList without normal array methods like map or forEach, so I find myself doing the following pretty much every time I use it: [...document.querySelectorAll('.example')] Typically I see people create a utility function $ (querySelector) and $$ (querySelectorAll with conversion to array). But this is fairly typical of the DOM API, some parts are awkwardly designed.
- destineddrip 2y agoFor what it’s worth, NodeLists do offer a forEach method (along with a few iterator returning methods which in contrast aren’t useful for concise style).
- 1GZ0 2y agoHold your horses now, you can absolutely do: document.querySelectorAll('.element').forEach(i => { yourFunction(i); }); I've not used map a whole lot, but I'm positive that it would work as well.
- lioeters 2y agoOh you're right, there is a forEach method. https://developer.mozilla.org/en-US/docs/Web/API/NodeList/forEach https://developer.mozilla.org/en-US/docs/Web/API/NodeList/fo... entries() forEach() item() keys() values() And maybe values().map() will work too.
- ehnto 2y agoAgreed, unless you need access to the plugin ecosystem perhaps. Most things are about as difficult in ES6 as they are with jQuery, so there's no huge benefit to jQuery in my experience.
- deleted 2y ago[deleted]