Skip to content

Instantly share code, notes, and snippets.

@lifeinafolder
Created November 16, 2010 19:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lifeinafolder/702391 to your computer and use it in GitHub Desktop.
Save lifeinafolder/702391 to your computer and use it in GitHub Desktop.
Currying Example 1
var arrayStore = []; //array to store the responses
// callback fn that is to be called after
// each JSONP call is successful
var callback = function(index,response){
arrayStore[index] = response;
};
var position = 0;
while( position < 5 ){
//wrapping my callback fn in an anonymous immediate fn
//to create closure for my incrementing variable position
JSONP(url,(function(pos){
return function(response){
callback(response,pos);
};
})(position));
position++;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment