4 ms·
I prefer:- function $(q, parent) { return (parent || document).querySelector(q); }
by zodiakzz 11y ago
I prefer:-
function $(q, parent) { return (parent || document).querySelector(q); }
- egeozcan 11y agoI'd also wrap it in a `[].slice.call`: function $(q, parent) { parent = parent || document; return [].slice.call(parent.querySelectorAll(q)); }
- marcoms 11y agoAlso see ES2015's Array.from() Array.from(<NodeList or other iterable>) https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/from https://developer.mozilla.org/en-US/docs/Web/JavaScript/Refe...