4 ms·
I have never heard of a case where I need to care about selector syntax errors. If it ever happened, I guess I'd just use a try? Much of the time "checking fo
by recursive 3y ago
I have never heard of a case where I need to care about selector syntax errors. If it ever happened, I guess I'd just use a try?
Much of the time "checking for null" consists of adding a single question mark.
document.querySelector("div#options")?.setAttribute("hidden", "true");
- troupo 3y ago> If it ever happened, I guess I'd just use a try? Exactly, you'd "just use a try". Instead of not using it. > Much of the time "checking for null" consists of adding a single question mark. Note: this API was introduced way before the `?` was even thought of. Which tells you a lot about the quality of the API. So. Just for the simple task of selecting elements: - you have to different APIs for "select 1 element"/"select multiple elements" - these APIs differ in their behaviour. They can also throw - almost none of the DOM APIs work with the return values of one of those APIs (e.g. your example stops working the second you use querySelectorAll) On top of that: - none of the DOM APIs can be chained, or combined in any meaningful way, so if you want to do more than just call one method, you're up for some very verbose and tedious boilerplate
- recursive 3y ago> Exactly, you'd "just use a try". Instead of not using it. This has happened zero times so far, to me. You can use qsa all the time if you want a consistent interface. I consider throwing to be a good thing if the input was bad. For me, none of these things represent a significant enough problem to take on another dependency. I'm probably doing different things than you. If JQuery solves some of your problems, I'm not trying to convince you to stop using it. I know you're asking/wishing it was the standard library. I don't even disagree, really.
- troupo 3y ago> This has happened zero times so far, to me. This has happened more than zero times to me. > You can use qsa all the time if you want a consistent interface. Indeed. And qsa is so much more verbose. Note how this whole discussion started with: - [jQuery] a collection of largely unnecessary (in modern times) utility functions for imperative DOM manipulation - It's still much easier to manipulate DOM with jQuery than with any of the "modern times" APIs My last statement is still a fact. "Modern" DOM APIs are anything but. They are the same 90s era OOP that is extremely verbose, cannot be composed in any meaningful way, and provides just a handful of somewhat useful utility functions that don't mean much in a grand scheme of things. There's a reason that even the most staunch of anti-framework people (like most of the web component crowd) immediately fall back do just dumping strings into DOM via .innerHtml