Hacker News new | ask | show | jobs
by nailer 3667 days ago
Well it's 2016 and we still don't have nodeList.forEach() so it can't be much worse.
4 comments

Actually, we do, since Chromium 51. See https://dev.opera.com/blog/opera-38/
Yeah you're right. Just updated stable Chrome and:

  NodeList.prototype.forEach
  forEach() { [native code] }
Thank. God. Finally.

Edit:

  HTMLCollection.prototype.forEach
(which is what you'll get from other vanilla JS methods) is still missing.
well we do have for..of that will iterate over a nodeList natively (and now that i'm using let/const i've found myself using for..of a lot more)
jQuery 3.0 lets you do for..of for a jQuery collection even.
Array.from(document.getElementBy...).forEach ?
There are ways to do it for sure, but imagine if there was just One Obvious Way To Do It.
Don't get me going on Python in the browser... :)
I 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.

1) 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

2. http://transcrypt.org

3. http://pyjs.org

4. http://www.rapydscript.com

From "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.

document.querySelectorAll(..).forEach?!?!?!?!
In 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.
Yep, that just rolls of the tongue...
Alias `document.querySelectorAll` to `$$`?
var $ = selector => [].slice.call(document.querySelectorAll(selector));

Fo' sizzle