“Menciptakan janji” Kode Jawaban

Menciptakan janji

JS
copy
let done = true

const isItDoneYet = new Promise((resolve, reject) => {
  if (done) {
    const workDone = 'Here is the thing I built'
    resolve(workDone)
  } else {
    const why = 'Still working on something else'
    reject(why)
  }
})
Aamir Farooq

Membuat janji

new Promise((resolve, reject) => {
  if (ok) { resolve(result) }
  else { reject(error) }
})
 
Motionless Mallard

JavaScript menjanjikan

var posts = [
  {name:"Mark42",message:"Nice to meet you"},
  {name:"Veronica",message:"I'm everywhere"}
];

function Create_Post(){
  setTimeout(() => {
    posts.forEach((item) => {
      console.log(`${item.name} --- ${item.message}`);
    });
  },1000);
}

function New_Post(add_new_data){
  return new Promise((resolve, reject) => {
    setTimeout(() => {
     posts.push(add_new_data);
      var error = false;
      if(error){
        reject("Something wrong in </>, Try setting me TRUE and check in console");
      }
      else{
        resolve();
      }
    },2000);
  })
}

New_Post({name:"War Machine",message:"I'm here to protect"})
    .then(Create_Post)
    .catch(err => console.log(err));
Outlander

Jawaban yang mirip dengan “Menciptakan janji”

Pertanyaan yang mirip dengan “Menciptakan janji”

Lebih banyak jawaban terkait untuk “Menciptakan janji” di TypeScript

Jelajahi jawaban kode populer menurut bahasa

Jelajahi bahasa kode lainnya