Answers for "js then"

4

js then

doSomething()
.then(function(result) {
  return doSomethingElse(result);
})
.catch(failureCallback);
Posted by: Guest on July-28-2021
1

promise catch

//create a Promise
var p1 = new Promise(function(resolve, reject) {
  resolve("Success");
});

//Execute the body of the promise which call resolve
//So it execute then, inside then there's a throw
//that get capture by catch
p1.then(function(value) {
  console.log(value); // "Success!"
  throw "oh, no!";
}).catch(function(e) {
  console.log(e); // "oh, no!"
});
Posted by: Guest on April-03-2020
4

then js

new Promise( (res, rej) => {
  setTimeout(() => res(1), 1000);
}).then( (res) => {
  console.log(res); // 1
  return res*2
}).then( (res) => {
  console.log(res); // 2
});
Posted by: Guest on September-14-2021
6

.then javascript

const promise2 = doSomething().then(successCallback, failureCallback);
Posted by: Guest on December-30-2020
1

js return a promise

function myAsyncFunction(url) {
  return new Promise((resolve, reject) => {
    const xhr = new XMLHttpRequest();
    xhr.open("GET", url);
    xhr.onload = () => resolve(xhr.responseText);
    xhr.onerror = () => reject(xhr.statusText);
    xhr.send();
  });
}
Posted by: Guest on July-23-2020

Code answers related to "Javascript"

Browse Popular Code Answers by Language