3 ms·
This is all I personally ever need. function $(q) { return document.querySelector(q) }
by vortico 11y ago
This is all I personally ever need.
function $(q) { return document.querySelector(q) }
- zodiakzz 11y agoI 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...
- bodhi 11y agoIf we're golfing, $ = document.querySelector.bind(document); would be sufficient? ;)
- takle 11y ago(var | let | const) $ = ::document.querySelector; with experimental ES7 syntax :D https://github.com/zenparsing/es-function-bind https://github.com/zenparsing/es-function-bind