“Twhat ist ein JS -Versprechen” Code-Antworten

JavaScript -Versprechen

var promise = new Promise(function(resolve, reject) {
  // do some long running async thing…
  
  if (/* everything turned out fine */) {
    resolve("Stuff worked!");
  }
  else {
    reject(Error("It broke"));
  }
});

//usage
promise.then(
  function(result) { /* handle a successful result */ },
  function(error) { /* handle an error */ }
);
Grepper

Twhat ist ein JS -Versprechen

const promise1 = new Promise((resolve, reject) => {
  setTimeout(() => {
    resolve('foo');
  }, 300);
});

promise1.then((value) => {
  console.log(value);
  // expected output: "foo"
});

console.log(promise1);
// expected output: [object Promise]
Anthony Smith

Was ist vielversprechend in JavaScript

Promises make async javascript easier as they are easy to use and write than callbacks. Basically , promise is just an object , that gives us either success of async opertion or failue of async operations
Odd Ox

Versprechen in js

myPromise
.then(handleResolvedA)
.then(handleResolvedB)
.then(handleResolvedC)
.catch(handleRejectedAny)
.finally(handleComplition)
Suman Majhi

Ähnliche Antworten wie “Twhat ist ein JS -Versprechen”

Fragen ähnlich wie “Twhat ist ein JS -Versprechen”

Durchsuchen Sie beliebte Code-Antworten nach Sprache

Durchsuchen Sie andere Codesprachen