Re:Bling – the $ of jQuery without the jQuery
by vortico on Monday June 15, 2015 @05:11AM
(#9718257)
This is all I personally ever need.
[ Parent
| on HN ]
Re:Bling – the $ of jQuery without the jQuery
by zodiakzz on Monday June 15, 2015 @05:12AM
(#9718263)
I prefer:-
function $(q, parent) { return (parent || document).querySelector(q); }
Re:Bling – the $ of jQuery without the jQuery
by egeozcan on Monday June 15, 2015 @05:36AM
(#9718344)
I'd also wrap it in a `[].slice.call`:
function $(q, parent) {
parent = parent || document;
return [].slice.call(parent.querySelectorAll(q));
}
Re:Bling – the $ of jQuery without the jQuery
by marcoms on Monday June 15, 2015 @09:45AM
(#9719210)
Also see ES2015's Array.from()
Array.from(<NodeList or other iterable>)
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Refe...If we're golfing,
$ = document.querySelector.bind(document);
would be sufficient? ;)(var | let | const) $ = ::document.querySelector;
with experimental ES7 syntax :D https://github.com/zenparsing/es-function-bind
Huh, my joke actually turned into me learning something, thanks!