Settings

Theme

Weaintfoundshit.js

nicosantangelo.github.io

63 points by NicoSantangelo · 21 comments

Reader

8 threads
antoineMoPa

I like the fact that it works with querySelectorAll! This is compatible with my projects in which I do:

    var qsa = function(sel){return document.querySelectorAll(sel)};
However, it does not work with:

    var subqsa = function(el,sel){return el.querySelectorAll(sel);}
  • maga

    If you're seriously wondering why is it so then, well, they're just replacing native methods of the document object, in order to get the same behavior from your second line, they'll have to replace Element.prototype.querySelectorAll as well, which is a bad idea.

  • nailer

    You can just:

      var queryAll = document.querySelectorAll.bind(document);
rossta

Thanks, there really aren't enough memes from Spaceballs these days.

aerovistae

I don't understand at all. I clicked "I don't get it," then put ".arbitrary" in as a selector, and.....a message comes up saying "Wasn't that awesome?" Nothing else happened.

What am I missing here

  • maga

    I believe it's a joke. At least I opened these comments thinking it was a joke akin to VanillaJS framework[1]. querySelectorAll returns an empty array if there are no matches, you don't need fancy string messages or errors for that.

    [1] http://vanilla-js.com/

    • atomwaffel

      > querySelectorAll returns an empty array if there are no matches, you don't need fancy string messages or errors for that.

      An empty NodeList[1] to be precise, which is sort of kind of like an array in that it has a length property and you can access its elements with index notation (`nodeList[0]`), but it doesn't inherit from Array.prototype, so it doesn't support methods like `forEach` or `map`.

      [1] https://developer.mozilla.org/en-US/docs/Web/API/NodeList

      • maga

        Indeed. Though still, NodeList has the length property with which you can check for "emptiness" the same as with an array, that's what I meant to say.

        Speaking of which, there are few features in ES2015 that make NodeList more palatable:

        1. Iterables. NodeList is iterable and you can use, among others, the for..of construction to iterate over its content.

        2. There is the Array.from method for turning array-like objects into true arrays. Not much different from our usual method of calling [].slice.call in this particular case, yet it's a bit shorter, standardized, and has a few additional perks, like accepting map function as the second argument.

      • ycitm

        At least in new versions of Chrome, NodeList is iterable, so you can use forEach and map on it.

        https://medium.com/@devlucky/nodelist-object-is-finally-an-i...

      • zackify

        [ ...document.querySelectorAll('nodes') ] will convert it to a real array ;)

    • NicoSantangeloOP

      You got it, it's just a joke :)

  • greyskull

    When I ran it, at least with the UI mode on the website itself, I get a mp4 of Spaceballs.

    https://nicosantangelo.github.io/weaintfoundshit.js/interact...

  • sb8244

    My best guess is you could raise an error and then you would always know if a selector didn't match.

    In jQuery, a selector which doesn't match will evaluate to true, where as .length would be 0. This is a source of bugs, I'm sure, especially for beginners.

asadlionpk

This is awesome! I wasn't expecting "I had enough" at all.

jondubois

Keep executing document.querySelector('.foo') several times in the dev console and eventually a new video comes up lol.

jereees

This should be tagged with "Show HN".

spilk

the mac keyboard shortcut listed should be Cmd+Option+i.

Hambonetasty

Spaceballs!

Keyboard Shortcuts

j
Next item
k
Previous item
o / Enter
Open selected item
?
Show this help
Esc
Close modal / clear selection