Skip to content

Instantly share code, notes, and snippets.

@Sigmus
Created October 26, 2012 18:49
Show Gist options
  • Save Sigmus/3960659 to your computer and use it in GitHub Desktop.
Save Sigmus/3960659 to your computer and use it in GitHub Desktop.
Run scripts sequentially using map/reduce and jQuery
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