Promise
が公式に仕様化されているので、次のスニペットの$q.defer()
プロミス作成を$q(function (resolve, reject) {})
コンストラクタ構文を代わりに使用するように変換するにはどうすればよいですか?
// Cancel any ongoing $http request so that only the most recent $http
// callback gets invoked
var canceller;
function getThing(id) {
if (canceller) canceller.resolve();
canceller = $q.defer();
return $http.get('/api/things/' + id, {
timeout: canceller.promise
});
}
($http docsからのFYI:timeout
は "ミリ秒単位で...、または解決したときに、要求を中止しなければならない約束。" である)
あなたの目標は何か分かりません。あなたのコードはうまく動作しているので、何も変更する必要はありません。 – Bergi
"*プロミスコンストラクタ構文を使用するには?*" - [**あなたはいません!**](http://stackoverflow.com/q/23803743/1048572) – Bergi
ゴールはありません。単なる学問的なエクササイズ – thatmarvin