Created
November 16, 2010 19:56
-
-
Save lifeinafolder/702391 to your computer and use it in GitHub Desktop.
Currying Example 1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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