Skip to content

Commit

Permalink
fix(promise-resolve): jQueryがロードされているページで動くコードに変更
Browse files Browse the repository at this point in the history
またjQueryに依存している事を明記

refs #273
  • Loading branch information
azu committed Nov 20, 2016
1 parent 934a479 commit 02cfd0b
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions Ch2_HowToWrite/promise-resolve.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,8 @@ https://api.jquery.com/jQuery.ajax/[jQuery.ajax()]の返り値もthenableです
このオブジェクトは `.then` というメソッドを持っているためです。

[source,javascript]
$.ajax('/json/comment.json');// => `.then` をもつオブジェクト
// このサンプルコードはjQueryをロードしている場所でないと動きません
$.ajax('http://httpbin.org/get');// => `.then` をもつオブジェクト

このthenableなオブジェクトを `Promise.resolve` ではpromiseオブジェクトにすることができます。

Expand All @@ -65,7 +66,8 @@ promiseオブジェクトにすることができれば、`then` や `catch` と
[source,javascript]
.thenableをpromiseオブジェクトにする
----
var promise = Promise.resolve($.ajax('/json/comment.json'));// => promiseオブジェクト
// このサンプルコードはjQueryをロードしている場所でないと動きません
var promise = Promise.resolve($.ajax('http://httpbin.org/get'));// => promiseオブジェクト
promise.then(function(value){
console.log(value);
});
Expand Down

0 comments on commit 02cfd0b

Please sign in to comment.