0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

Promiseオブジェクトの関数に引数を使用する【編集中】

Last updated at Posted at 2020-04-17

ポイント
(1) Promiseオブジェクトをreturnする関数にする
(2) 実行処理で引数指定

元のコード.js
var getRoomData = new Promise(function(resolve,reject){
    roomInfo.on('value', (snapshot)=> {
        resolve(snapshot.val())
    });

    ・・・省略・・・

getRoomData.then(function(dbData){
    ・・・省略・・・
})
正しいコード.js
var getRoomData = function(roomInfo){ //(1) Promiseオブジェクトをreturnする関数にする
    return new Promise(function(resolve,reject){
            roomInfo.on('value', (snapshot)=> {
                resolve(snapshot.val())
            });
        })

    ・・・省略・・・
 
}
getRoomData(roomInfo).then(function(dbData){ //(2) 実行処理で引数指定
    ・・・省略・・・
})
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?