Created
October 26, 2012 18:49
-
-
Save Sigmus/3960659 to your computer and use it in GitHub Desktop.
Run scripts sequentially using map/reduce and jQuery
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 files = [ | |
'first.js', | |
'second.js', | |
'third.js', | |
'fourth.js' | |
]; | |
var funcs = files.map(function(file) { | |
return function() { return $.getScript(file); } | |
}); | |
var deferred = $.Deferred(); | |
funcs.reduce(function (soFar, f) { | |
return soFar.then(f); | |
}, deferred.resolve(funcs[0])); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment