4 ms·
From bevr1337's comment, above: > its API was a reflection of the domain. As a developer, I want to query for a node (CSS selector, xpath, etc.) to affect chan
by eszed 1y ago
From bevr1337's comment, above:
> its API was a reflection of the domain. As a developer, I want to query for a node (CSS selector, xpath, etc.) to affect change and traverse to other nodes
That's what I miss about it.
- jraph 1y agoDoesn't querySelector(All) provide this?
- troupo 1y agoNot entirely. There's a reason people do Array.from(querySelectorAll) to do more than just `forEach`
- jraph 1y agoSo you are saying that Array.from(querySelectorAll) gets you there? What are you missing then? Genuinely asking, I have no clue what's being alluded to without being clearly mentioned in this thread.
- troupo 1y ago> So you are saying that Array.from(querySelectorAll) gets you there? What are you missing then? Array.from adds friction. The need to wrap querySelector in null checks adds friction. The fact that they are not composable in any way, shape, or form, with any DOM methods (and that DOM methods are not composable) adds friction. jQuery was the fore-runner of fluid interface design. Nothing in the DOM before, then, or since ever thought about it. Even the new APIs are all the same 90s Java-style method calls with awkward conversions and workarounds to do anything useful. That's why sites like "You don't need jQuery" read like bad parody: https://youmightnotneedjquery.com https://youmightnotneedjquery.com E.g. what happens when it's not just one element? $(el).addClass(className); // vs. el.classList.add(className); Or: why doesn't NodeList expose an array-like object, but provides an extremely anaemic interface that you always need to convert to array? [1] $(selector).filter(filterFn); // vs. [...document.querySelectorAll(selector)].filter(filterFn); There's a reason most people avoid DOM APIs like the plague. --- [1] This is the entirety of methods exposed on NodeList https://developer.mozilla.org/en-US/docs/Web/API/NodeList https://developer.mozilla.org/en-US/docs/Web/API/NodeList Instance properties - length Instance methods - entries() // returns an iterator - forEach() - item() - keys() - values()
- jraph 1y agoI agree that DOM lists not being real arrays is a pita. I can understand why for getElementBy* methods which return live lists, but it's less clear for those methods returning fixed lists. But to me, these are minor inconveniences and habits. A thin wrapper can get you there easily if you care enough. I personally dislike this array/element confusion that jQuery adds.
- troupo 1y ago> A thin wrapper can get you there easily if you care enough But that's more and more friction. A wrapper here, a wrapper there, and if here, a try/catch there. At one point you are reinventing significant chunks of jQuery
- jraph 1y agojQuery's scope is broad¹. It has at least: - a plugin system - its custom selector parser (because it had it before querySelector and is not totally compatible with it) - its abstraction to iron out browser differences (old IE vs standard, notably) that's not relevant anymore - its own custom (DOM) event management - its implementation of methods that are now standard (ajax & trim for instance) I recognize that the DOM API could be better, and comes with friction. Back then, ironing out the browser differences and its selector feature were killer features of jQuery. Today, I do not think the quirks of the DOM API warrant importing a library like jQuery. ¹ but indeed, very lightweight compared to modern frameworks like Angular, React and Vue, with all the ecosystem which comes with each of them (react-router, redux, etc).
- lofaszvanitt 1y agoquack quack quack... why reinvent the wheel, why not adopt a good, working system, why the need to do everything in a complicated way? give resig a big black suitcase full of money and implement his complexity reduction framework called jQuery into the standard. And fire the standards guys in the process, because what they do is shit. they most presumably never worked extensively with the shit they produce.