Skip to content

Comment on A Dive Into Plain JavaScript

Comments

* Why feature detect classList with `if ("classList" in document.documentElement)` and not `!! document.documentElement.classList` like described at the beginning of the article?

* Why add a style to a cloned node instead of directly to the node? Performance improvements?

* `$ = document.querySelectorAll.bind(document);` won't let you have a shorthand for performing a query selector on an element. For that, you also need something like `Element.prototype.$ = Element.prototype.querySelectorAll;`. Likewise, you'll probably want the `on` shorthand applied to document and window too for consistency's sake.

* I also like to cast Array's forEach method to NodeList to iterate over values from a querySelectorAll. That way you can do $('a').forEach() instead of [].forEach.call($('a'), function(el)).

You could also just convert the NodeList to an array by running something like

    [].slice.call(nodeList)
That way you get all array methods, not just forEach.
AboutSource Built by g1lg1l

Hackerly is an independent reader for Hacker News, built on the public HN API. Not affiliated with Y Combinator.