4 ms·
document.querySelectorAll(..).forEach?!?!?!?!
by nathggns 10y ago
document.querySelectorAll(..).forEach?!?!?!?!
- robodale 10y agoYep, that just rolls of the tongue...
- mratzloff 10y agoAlias `document.querySelectorAll` to `$$`?
- MrPatan 10y agovar $ = selector => [].slice.call(document.querySelectorAll(selector)); Fo' sizzle
- abritinthebay 10y agoIf you're using ES6 you may as well use spread and defaults to make it more useful: const $ = (selector, context=document) => [...context.querySelectorAll(selector)]
- nailer 10y agoOr 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().
- calebegg 10y agoIn Firefox, Safari, IE, and Chrome < 51: TypeError: document.querySelectorAll(...).forEach is not a function That's exactly what this sub-thread is about! NodeList doesn't have .forEach.