3 ms·
I still think the jQuery API is significantly easier than the DOM one. querySelectorAll() returns this NodeList object that's much harder to use than it needs t
by arp242 6y ago
I still think the jQuery API is significantly easier than the DOM one. querySelectorAll() returns this NodeList object that's much harder to use than it needs to be. Things like getting the next sibling is much harder than jQuery's .next(), etc. etc.
I also don't care much for the fetch() API; I dislike promises and what does it send when you try to POST a JS object ({foo: 'val'})? [object Object]. Yeah, useful...
And even in 2021-jQuery, it still works around some browser bugs and inconsistencies, even in modern browsers. Much less than it used to, but not zero either.
- jarek-foksa 6y agoWith modern JavaScript you can easily cast a NodeList to an Array, e.g. `let spansArray = [...element.querySelectorAll("span")]`. I find both `element.nextElementSibling` and `element.next()` to be examples of poor API design. The former one is more verbose than needed while the latter one is so short you can't even tell whether it's a method or a property.
- porker 6y ago> With modern JavaScript you can easily cast a NodeList to an Array, e.g. Ah, thanks. I got bitten by this recently and didn't know what to do with this "thing that's not an array but seems like it should be, and doesn't always behave like one"
- nicoburns 6y agoFYI the reason it's not an array is because if you store a reference to it, it will stay up to date as and when the DOM changes.
- jarek-foksa 6y agoThe NodeList returned by querySelectorAll() is not live. There is really no reason for it to return a NodeList other than backward compatibility.
- spiralx 6y agoBefore that ES2015 allowed you to do Array.from(nodeList, mapFunc?) which I still use due to the optional mapping function e.g. Array.from(document.querySelectorAll('a'), a => a.href)
- names_are_hard 6y agoIf you dislike promises, what do you prefer? Callbacks? Why?
- arp242 6y agoBecause it's a lot clearer what gets run in what order.
- spiralx 6y agoHow? It's about the same if you have one callback maybe, but as soon as you have a callback within a callback - or worse, want to do something involving the results of more than one callback - I just can't see it. What's the advantage of what's often referred to as "callback hell" for you?