「JavaScript」Promiseを使用するサンプル

環境
Google Chrome 105.0.5195.12
Windows 10 home 64bit
構文
1.Promiseオブジェクトを生成します。
return new Promise((resolve) => {
処理コード
});
2.関数名()
.then(処理コード)
resolvedの時はthenで受ける必要があります。

使用例

function funA() {
  //Promiseオブジェクトを生成
  return new Promise((resolve) => {
    resolve("this is a test");
  });
}
funA()
//then
  .then((strA) => {
    console.log(strA); 
});

実行結果
> “this is a test"

JavaScript

Posted by arkgame