Last active
May 29, 2016 04:37
-
-
Save nishinoshake/7b0e0e1d7b99e75b4fba to your computer and use it in GitHub Desktop.
Deferredによる非同期処理
This file contains hidden or 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 | |
順番待ち的な処理が簡単に実装できる。 | |
1.Deferredオブジェクトを生成してとりあえず返す(return d.promise()) | |
2.処理が正常終了したら合図を返す(d.resolve()) | |
3.失敗しても合図を返す(d.reject()) | |
4.thenでつなげると前段の状態変化を待って実行できる | |
(then()はdone()とfail()をまとめて実行できる) |
This file contains hidden or 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
function sample() { | |
df().then(function() { | |
}); | |
} | |
function df() { | |
var d = new $.Deferred; | |
$("sample").fadeIn(200, function() { | |
d.resolve(); //d.reject('Error!!'); | |
}); | |
return d.promise(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment