Hacker News new | past | comments | ask | show | jobs | submit login

Alias `document.querySelectorAll` to `$$`?



var $ = selector => [].slice.call(document.querySelectorAll(selector));

Fo' sizzle


If you're using ES6 you may as well use spread and defaults to make it more useful:

const $ = (selector, context=document) => [...context.querySelectorAll(selector)]


Or just polyfill it with NodeList.prototype.forEach = Array.prototype.forEach and get nice readable code.

Point is: we shouldn't have to.

Vanilla JS also allowed you to look inside HTML5 FormData a few months earlier. And no, it isn't FormData.toString().




Join us for AI Startup School this June 16-17 in San Francisco!

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: