Skip to content

Instantly share code, notes, and snippets.

@ashleycoker
Last active April 27, 2018 17:31
Show Gist options
  • Save ashleycoker/81fc23a107d98d3eb4232e93a2f6ca59 to your computer and use it in GitHub Desktop.
Save ashleycoker/81fc23a107d98d3eb4232e93a2f6ca59 to your computer and use it in GitHub Desktop.
function createOperations(){
var operations = [];
for (var i = 0; i < 5; i++) {
operations.push(function(input){
return input * i;
})
}
return operations;
}
var ops = createOperations();
for (var i = 0; i < 5; i++) {
alert(ops[i](i));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment