Joined June 2012
·

Tom Ashworth

Buffer
·
UK
·
·
·

Nice. There's a couple of things I'd tweak though.

  • The function is called getEls, but you sometimes return multiple elements, and sometimes only one. It should be consistent, so that the user of the method doesn't have to check if what they got back was a NodeList or some kind of Element.
  • I have no proof of this, but I suspect passing sel || ☺ is inefficient. It'd be better to return early if no selector is passed. You could even return an empty NodeList using document.createDocumentFragment().childNodes
  • I'd recommend taking a boolean argument that, if true, forces it to bypass the cache and save that selector again.

I think it's important to note that this also removes the elements from the array.

Achievements
158 Karma
0 Total ProTip Views