📜  承诺 javascript 代码示例

📅  最后修改于: 2022-03-11 15:01:41.986000             🧑  作者: Mango

代码示例6
let num = 10;
//call back function
const promis = new Promise(function (resolve, reject) {

  if (num > 5) {

    //this resolve method will send data to resoleveData variable
    resolve(" Problem resolved successfully")
  }
  else {
    //this reject method will send data to rejectData variable
    reject("sorry problem couldn't solve")
  }

})
//resoleveData variable
promis.then(function (resolveData) {

  console.log(resolveData)
  //rejectData variable
}).catch(function (rejectData) {

  console.log(rejectData)
})