Your example shows how the author's conclusions are wrong. IMHO the biggest milestones of Javascript life have been his libraries and the creative uses we have seen around them. From XMLHttpRequest to jQuery (and Prototype, Mootools, etc) and now Node.JS there have been highly disruptive innovations over this basically flawed language.
Maybe we should give more attention to the basic process behind this, creating libraries aka Programming Motherfucker.
Actually, the forEach version can end up faster than the let version... especially if you self-host forEach so that the JIT can do its job (e.g. inlining the LIB_addEventListener calls so there aren't actually any function invocations, etc).
> Actually, the forEach version can end up faster than the let version...
Theoretically maybe, but I've yet to see that. A regular `for(;;)` is generally 3-5 times faster than using `Array.prototype.forEach`.
Re. JIT, hand-rolling a foreach in javascript can be up to twice as fast as the native one, depending on the features you leave out.
Re:JavaScript is Dead. Long Live JavaScript
by bzbarsky on Tuesday June 28, 2011 @02:56PM
(#2706748)
> Theoretically maybe, but I've yet to see that
Compare the let version to the code in https://bugzilla.mozilla.org/show_bug.cgi?id=602132
Mozilla introduced this back in Firefox 2, and you can replace var with it, so TFAA's
becomes: Of course, since this does not quite seem to be a tight loop you should be using Array.prototype.forEach instead: > The JavaScript idiom that potentially spans the most lines of your program may be the inheritance idiom.That's not an idiom. And there are numerous implementations of classes on top of prototypes out there, if there's one javascript "problem" which does not need new syntax it's that one.