Skip to content

Instantly share code, notes, and snippets.

@radamant
Created August 23, 2010 15:14
Show Gist options
  • Select an option

  • Save radamant/545684 to your computer and use it in GitHub Desktop.

Select an option

Save radamant/545684 to your computer and use it in GitHub Desktop.
var numbers = [1,2,3,4];
var numObject = {
1: 1,
2: 2,
3: 3,
4: 4
}
var funcs = [];
funcs.push(function(){console.log("from array")})
$(numbers).each(function(i, item){
var number = item;
funcs.push(function(){
console.log(number * number);
});
});
funcs.push(function(){console.log("from object")})
for(index in numObject){
var number = numObject[index];
funcs.push(function(){
console.log(number * number);
});
}
$(funcs).each(function(i, item){
item();
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment