3 ms·
In case of `query` you’d have a uniform API from which all other APIs would flow. That’s what $ essentially is. Instead, browser have two incompatible APIs: `q
by dmitriid 7y ago
In case of `query` you’d have a uniform API from which all other APIs would flow. That’s what $ essentially is.
Instead, browser have two incompatible APIs: `querySelector` to retrieve one item only, and `querySelectorAll` to retrieve multiple items.
On top of that, jQuery always returns an array-like object. `querySelectorAll` returns a NodeList that is so poorly designed that it didn’t have a `.forEach` for two years or so, and you’re still better of doing an `Array.from` on it for the sake of consistency and sanity.
For every thing that jQuery got right, browsers got 10 things wrong. For every thing that jQuery got wrong, browsers got 100 things wrong. It took browsers 7 years to implement querySelector/querySelectorAll after jQuery showed it’s possible and useful. And they still got it wrong. 13 years after jQuery debuted DOM APIs are still a mishmash of extremely poorly designed functions that are unnecessarily verbose and error prone.
- partialrecall 7y agoObviously a poorly designed API is inexcusable, but I don't think the verbosity of function or variable names is the cause of that.
- dmitriid 7y agoTrue, it’s the symptom (in many, but not all cases)
- earthboundkid 7y agoThis criticism makes no sense. If you always want an Array-like object, just always use querySelectorAll. If you don't then don't. Why is it bad that the DOM gives you a choice instead of giving you a pseudo-array that sometimes acts like an element and sometimes not? The DOM more clearly separates NodeList from Element than JQuery, and that's good! I agree that not having forEach by default was a mistake, but it's long since been solved.
- dmitriid 7y ago> If you always want an Array-like object, just always use querySelectorAll `querySelectorAll` doesn’t even return an array-like object. It took w3c almost two years to add a forEach to it. It’s also so badly designed that MDN docs has a whole section oh how it behaves with unexpected results and how, quote “to restore expected behavior”. So all perceived benefits (like the separation between Element and NodeList) are badly contrived and trumped by how badly they are designed in comparison with a 15-year old library whose core API was designed by one person.