“JS Promise API” Kode Jawaban

Janji JavaScript

let promise = new Promise(function(resolve, reject){
  try{
  	resolve("works"); //if works
  } catch(err){
    reject(err); //doesn't work
  }
}).then(alert, console.log); // if doesn't work, then console.log it, if it does, then alert "works"
Unusual Unicorn

JS Promise API

const fetchData = () => {
  fetch('https://api.github.com').then(resp => {
    resp.json().then(data => {
      console.log(data);
    });
  });
};
Puzzled Puffin

js janji

const executorFunction = (resolve, reject) => {
  if (someCondition) {
      resolve('I resolved!');
  } else {
      reject('I rejected!'); 
  }
}
const myFirstPromise = new Promise(executorFunction);
Anthony Smith

Jawaban yang mirip dengan “JS Promise API”

Pertanyaan yang mirip dengan “JS Promise API”

Lebih banyak jawaban terkait untuk “JS Promise API” di JavaScript

Jelajahi jawaban kode populer menurut bahasa

Jelajahi bahasa kode lainnya