5 ms·
Array.from(document.getElementBy...).forEach ?
by eyko 10y ago
Array.from(document.getElementBy...).forEach ?
- Jgrubb 10y agoThere are ways to do it for sure, but imagine if there was just One Obvious Way To Do It.
- rcarmo 10y agoDon't get me going on Python in the browser... :)
- andybak 10y agoI can't find a reference but I remember hearing a tale that Guido was contacted by Netscape just before Brendan Eich but wasn't interested. What an interesting parallel reality that conjours up. Hmmmm. On second thoughts maybe we're be living in a world where Python was as maligned as Javascript.
- smt88 10y ago1) There's certainly not "one way" to iterate in Python[1], and they're not even consistently named (xrange is the iterator version of range, but izip is the iterator version of zip). 2) You can use Python in the browser[2][3][4 sort of]. 1. https://youtu.be/OSGv2VnC0go?t=3m20s https://youtu.be/OSGv2VnC0go?t=3m20s 2. http://transcrypt.org http://transcrypt.org 3. http://pyjs.org http://pyjs.org 4. http://www.rapydscript.com http://www.rapydscript.com
- djsumdog 10y agoFrom "import this" > There should be one-- and preferably only one --obvious way to do it. Key words are preferably and obviously. Of course there are going to be multiple ways to do everything, but it'd be nice if the best practice is pretty obvious. > Although that way may not be obvious at first unless you're Dutch.
- nathggns 10y agodocument.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.