Skip to content

Instantly share code, notes, and snippets.

@lifeinafolder
Created November 16, 2010 21:23
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/702538 to your computer and use it in GitHub Desktop.
Save lifeinafolder/702538 to your computer and use it in GitHub Desktop.
Currying Example 2
//The curry function that we will use.
var _curry = function() {
var args = Array.prototype.slice.call(arguments);
var fn = args.shift();
return function() {
return fn.apply(this, args.concat(
Array.prototype.slice.call(arguments)));
};
};
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 ){
//pre-filling callback function(with current position
//value) to be called later when the JSONP call returns
JSONP(url,_curry(callback,position));
position++;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment