Hacker News new | ask | show | jobs
by hackerboos 4081 days ago
This only supports IE10+. Why shouldn't I just use Javascript directly?
2 comments

Not the author, but the API still sucks to write using vanilla JS. There are also still plenty of inconsistencies in modern browsers (per an article floating around here in the last day or two).
> the API still sucks

If you want syntactic sugar, a better alternative to a client-side library (which has overhead) is to use something like TypeScript (or one of the other compile-to-JavaScript options).

they solve different problems though... syntactic sugar from TypeScript et al solve problems with Javascript the language

jQuery solve problems with the various builtin APIs like DOM etc that are part of either Javascript or the web browser host

I just assumed the person I was replying to was complaining about document.getElementById('whatever') (etc.) vs $('#whatever').

In response to your comment, polyfills are more future-proof solutions to browser compatibility, which is the only remaining problem that I see jQuery as solving well.

> I just assumed the person I was replying to was complaining about document.getElementById('whatever') (etc.) vs $('#whatever')

Actually that is what I was referring to. I must not have given TypeScript enough of a shake. I couldn't find the section in the early tutorial that showed me that sugar, and I also couldn't figure out how the typing stuff would help me working with a bunch of network-y type apps. Obviously this is my own failing. Inspired now to give it another shot, so thanks.

It's entirely my own fault, but this has been a really muddled conversation.

When I mentioned TypeScript, I only meant that it (and other languages that compile to JavaScript, like Go) is a better syntax overall. I didn't actually mean that it helps with DOM selection/manipulation.

So if you want short DOM syntax, I'd suggest using vanilla ES6[1] with polyfills, and then figure out what's really wasting your time. Then, you can write your own sugar for it.

In my opinion, document.getElementById is something that you end up writing a lot and is really long, but with autocomplete in a good IDE, it's not a big deal. Plus, any JS developer who sees it will know exactly what it does and what it returns.

1. https://babeljs.io

The DOM API remains complete garbage unless you're operating readonly on a single node (then it's merely bad).
Do you have any examples? In my opinion the DOM API only sucked pre-IE9 because of all the inconsistencies and incompatibilities.

I have dropped jQuery completely except for when I need some of its plugins because I end up having to access the internal DOM objects too often and using $el.get(0) all over the place is ugly and a PITA.

    $('.something').toggleClass('collapsed')
                   .click(somethingClicked);
This simple and readable statement will turn into a lot of lines with DOM API.