Skip to content

Instantly share code, notes, and snippets.

@vicatcu
Created August 28, 2015 15:09
Show Gist options
  • Save vicatcu/7dde5bcb09d4ffac989e to your computer and use it in GitHub Desktop.
Save vicatcu/7dde5bcb09d4ffac989e to your computer and use it in GitHub Desktop.
var commandList = ["a", "b", "c"];
var commandFuncs = [];
for(var i = 0; i < commandList.length; i++){
var cmd = commandList[i];
commandFuncs.push( function(callback){
setTimeout(function(){
console.log(cmd);
callback(null);
}, 500);
}
);
}
for(var i = 0; i < commandList.length; i++){
commandFuncs[i](null);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment