To make closures inside loops a little more descriptive:
for(var i = 0; i < 5; i++) {
freeze(i, function(i) {
setTimeout(function() {
console.log(i);
}, 1000);
});
}
function freeze() { | |
var args = Array.prototype.slice.call(arguments); | |
return args.pop().apply(this, args); | |
} |