News for hackers. Stuff that matters.
Re:JavaScript is Dead. Long Live JavaScript by masklinn on Sunday June 26, 2011 @09:09AM (#2697951)
> If your application uses the let idiom, wouldn’t it be nice to have new syntax for it?

Mozilla introduced this back in Firefox 2, and you can replace var with it, so TFAA's

    for (var i=0, ilen=elements.length; i<ilen; i++) {
        var element = elements[i];
        let (num = i) {
            LIB_addEventListener(element, function(event) {
                alert('I was originally number ' + num);
            });
        };
    }
becomes:

    for (let i=0, ilen=elements.length; i<ilen; i++) {
        let element = elements[i];
        LIB_addEventListener(element, function(event) {
            alert('I was originally number ' + i);
        });
    }
Of course, since this does not quite seem to be a tight loop you should be using Array.prototype.forEach instead:

    elements.forEach(function (element, i) {
        LIB_addEventListener(element, function(event) {
            alert('I was originally number ' + i);
        });
    });
> 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.

Re:JavaScript is Dead. Long Live JavaScript by jacabado on Sunday June 26, 2011 @06:04PM (#2699244)
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.

Re:JavaScript is Dead. Long Live JavaScript by bzbarsky on Monday June 27, 2011 @12:00AM (#2700050)
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).
Re:JavaScript is Dead. Long Live JavaScript by masklinn on Monday June 27, 2011 @02:36AM (#2700388)
> 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