HN2new | past | comments | ask | show | jobs | submitlogin

More specifically, how JavaScript can do a lot in browser by interacting through the DOM API.

The modernization of the DOM API in the last 5 years has done a lot to remove the need for jQuery et al, and has made building the View part of JavaScript apps much more frictionless.



Where can we learn about this “modern JS“? I feel like in some ways I’m learning the old ways, similar to old c++.


The parent isn't talking about JS: they're talking about the DOM APIs. The best resource I've found for learning about these is MDN: https://developer.mozilla.org/en-US/docs/Web/API/Document_Ob.... I've found this to be an incredibly helpful reference when I need to do something without using a library.


Following the tc39 proposals on GitHub is a great way to keep up with features just being added. "What's new in ES2020" type blog posts should catch you up between then and the bleeding edge. MDN for actually getting the technical details on things as you try to implement the features you read about (will also xover browser specific APIs). caniuse to see if they are actually ready to be used.


It's both modern Web APIs as well as ES6 JavaScript, both of which make working in VanillaJS quite pleasant.

If you don't need to support older browsers, you don't even need to use any packaging software (although if you're building a serious app, it's still wise to do so). You can import ES6 modules in vanilla JS, and a modern browser will do the loading for you. Great for quick starts.


You still end up re-implementing half of jQuery. Because element creation is just as much passion as it was in 1999. Because useful functions are limited or stunted compared to jQuery counterparts (querySelectorAll returns a weird object instead of an array and throws exceptions if you as as much as as look at it funny, etc.).


Either iterate through the `NodeList` with a `for ... of` loop or a `.forEach` method, or convert it to an array using `Array.from()` or `[...nodeList]`.

`NodeList` can be a live list (not `querySelectorAll` though) which has some benefits over arrays.

`NodeList` also implements `Symbol.iterator` so you can use your favorite iterator library if you need to map, filter or reduce it. And with the future pipeline operator, you’ll really don’t see a different between a standard array and a fancy structure like `NodeList`.


[flagged]


Well, you called it a "weird object" that throws errors if you "look at it funny." They tried to demystify it for you in just three sentences.

That jQuery lets you willfully cling to the corpse of familiarity instead of spending 30 seconds looking up what NodeList was years ago says more about you than anything about jQuery.

And with your end-cap comment about the pipeline operator that they were already, helpfully, pointing out was going to be introduced in the future, you just sound like sour grapes. What gives? Kind of a weird attitude to bring to a forum of craftspeople.


> Well, you called it a "weird object" that throws errors if you "look at it funny." They tried to demystify it for you in just three sentences.

I never said it was mysterious to me. I described it as concisely as possible. It is an object that has a grand total of two array-like methods (and it took the standards bodies two years to add forEach to it). And it does throw an exception on invalid input.

So, to work with it without hassle, guess what, you'll have to recreate that "corpse of familiarity" from jQuery: throw an Array.from at it, and wrap it in a try-catch.

And that is true for every single improvement to the DOM API. If you look at all the efforts to get rid of jQuery, you'll see people re-implementing half of it for one simple reason: all the improvements are still stunted, underdesigned, and need quite a lot of additional boilerplate to make it useable in any hut the simplest scenarios. (Notable exception: classList. It weirdly behaves and works the way that doesn't screw up developer experience).

> And with your end-cap comment about the pipeline operator that they were already, helpfully, pointing out was going to be introduced in the future, you just sound like sour grapes. What gives?

The pipeline operator proposal has been there for three years. Excuse me for not jumping with joy when someone quips that there will be no difference between arrays and NodeLists in some glorious future. I prefer reality.


ha, i just went through this today, querySelectorAll returns a NodeList, which is static rather than live, requiring you to iterate through the list rather than acting on the elements directly.

but it's nice that jquery (as convenient as it is) is no longer a must-have library for dom manipulation.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: