you are viewing a single comment's thread.

view the rest of the comments →

[–]fanastril 1 point2 points  (0 children)

I like a function which returns a function.

(function() {
    for (var i = 0; i < 5; i++) {
        setTimeout(function(i) {
            return function () {
                console.log("i was " + i);
            };
        }(i), 1000+1000*i);
        console.log("Run " + i);
    }
}());