Created
November 16, 2010 21:23
-
-
Save lifeinafolder/702538 to your computer and use it in GitHub Desktop.
Currying Example 2
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
//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