Skip to content

Instantly share code, notes, and snippets.

@HituziANDO
Last active April 6, 2016 08:15
Show Gist options
  • Save HituziANDO/6909d8dc8ccf1f7bcec30b78f8b23435 to your computer and use it in GitHub Desktop.
Save HituziANDO/6909d8dc8ccf1f7bcec30b78f8b23435 to your computer and use it in GitHub Desktop.
jQuery.whenにQ.allのように配列でDeferredを渡す方法
/**
* jQuery.whenにQ.allのように配列でDeferredを渡す関数
*
* @param deferredList Array of jQuery.Deferred object
* @returns jQuery.Promise object
*/
function $all(deferredList) {
return $.when.apply(null, deferredList);
}
// 使い方
// $all([
// $.get('/path/to/data1.json'),
// $.get('/path/to/data2.json')
// ]).done(function(data1, data2) {
// // Do something
// }).fail(function() {
// // Do something
// }).always(function() {
// // Do something
// });
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment