Live data from Hacker News

Bling – the $ of jQuery without the jQuery

gist.github.com

1–10 of 138 posts

Re: Bling – the $ of jQuery without the jQuery

#2
This does three things:

1. Alias document.querySelectorAll to $. 2. Alias node.on to node.addEventListener. 3. Make NodeList a sub-type of Array (so you can use forEach etc on node lists as you would on arrays).

The $ of jQuery also does a few other things, e.g. create HTML elements from text ($('') creates a div element with CSS class "foo") and wrap elements in a node list ($(document.body) creates a node list containing document.body).

Re: Bling – the $ of jQuery without the jQuery

#5
I don't really know what to think about that.

On one hand it may be a nice way to show to people that what they use in jQuery can be written in a few lines of pure JS.

On the other hand it encourages people who could use pure JS (because they only use a small portion of jQuery) to stick with some non-standard helper syntax.

Re: Bling – the $ of jQuery without the jQuery

#8
post #5

I don't really know what to think about that. On one hand it may be a nice way to show to people that what they use in jQuery can be written in a few lines of pure JS. On the other hand it encourages people who could use pure JS (because they only use a small portion of jQuery) to stick with some non-standard helper syntax.

> to stick with some non-standard helper syntax.

Or in other words - replacing an ugly, verbose API with a widely recognised alternate syntax!

Re: Bling – the $ of jQuery without the jQuery

#9
post #4
post #3

This is all I personally ever need. function $(q) { return document.querySelector(q) }

I prefer:- function $(q, parent) { return (parent || document).querySelector(q); }

I'd also wrap it in a `[].slice.call`:

    function $(q, parent) {
        parent = parent || document;
        return [].slice.call(parent.querySelectorAll(q));
    }
Post reply on HN