Created
October 10, 2012 10:37
-
-
Save YusukeHirao/3864682 to your computer and use it in GitHub Desktop.
可変長引数で渡したコールバック関数を$.Deferred().pipe()で直列処理 ref: http://qiita.com/items/03364b0e82975a03dec6
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
$.Deferred().pipe(function () { | |
// なんらかの処理 | |
// ajaxとかanimateとかdeferredとかのpromiseしたjQueryオブジェクトを返す。 | |
// (※それらの処理がresolveされた時点で次のpipeに登録した関数が実行される) | |
return promised; | |
}).pipe(function () { | |
// なんらかの処理 | |
// ajaxとかanimateとかdeferredとかのpromiseしたjQueryオブジェクトを返す。 | |
// (※それらの処理がresolveされた時点で次のpipeに登録した関数が実行される) | |
return promised; | |
}).pipe(function () { | |
// なんらかの処理 | |
// ajaxとかanimateとかdeferredとかのpromiseしたjQueryオブジェクトを返す。 | |
// (※それらの処理がresolveされた時点で次のpipeに登録した関数が実行される) | |
return promised; | |
}).resolve(); |
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 sequence = function () { | |
var dfd, | |
piped, | |
i, | |
l = arguments.length; | |
dfd = $.Deferred(); | |
for (i = 0; i < l; i += 1) { | |
if ($.isFunction(arguments[i])) { | |
piped = (piped ? piped : dfd).pipe($.proxy(function () { | |
return this(); | |
}, arguments[i])); | |
} | |
} | |
dfd.resolve(); | |
}; | |
sequence( | |
function (){ | |
// なんらかの処理 | |
// ajaxとかanimateとかdeferredとかのpromiseしたjQueryオブジェクトを返す。 | |
// (※それらの処理がresolveされた時点で次のpipeに登録した関数が実行される) | |
return promised; | |
}, | |
function (){ | |
// なんらかの処理 | |
// ajaxとかanimateとかdeferredとかのpromiseしたjQueryオブジェクトを返す。 | |
// (※それらの処理がresolveされた時点で次のpipeに登録した関数が実行される) | |
return promised; | |
}, | |
function (){ | |
// なんらかの処理 | |
// ajaxとかanimateとかdeferredとかのpromiseしたjQueryオブジェクトを返す。 | |
// (※それらの処理がresolveされた時点で次のpipeに登録した関数が実行される) | |
return promised; | |
} | |
); |
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
sequence( | |
-> | |
# なんらかの処理 | |
# ajaxとかanimateとかdeferredとかのpromiseしたjQueryオブジェクトを返す。 | |
# (※それらの処理がresolveされた時点で次のpipeに登録した関数が実行される) | |
promised | |
-> | |
# なんらかの処理 | |
# ajaxとかanimateとかdeferredとかのpromiseしたjQueryオブジェクトを返す。 | |
# (※それらの処理がresolveされた時点で次のpipeに登録した関数が実行される) | |
promised | |
-> | |
# なんらかの処理 | |
# ajaxとかanimateとかdeferredとかのpromiseしたjQueryオブジェクトを返す。 | |
# (※それらの処理がresolveされた時点で次のpipeに登録した関数が実行される) | |
promised | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment