var funcs = [], i = 0; while (i<10) { (function (j) { funcs.push(function(){ console.log(j); }); })(i); i++; }