Skip welcome & menu and move to editor
Welcome to JS Bin
Load cached copy from
 
<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <title>JS Bin</title>
</head>
<body>
  <h1>Look at the console</h1>
  
  <button type="button" onclick="example1()"><h2>Run example #1</h2></button>
  <button type="button" onclick="example2()"><h2>Run example #2</h2></button>
  <button type="button" onclick="example3()"><h2>Run example #3</h2></button>
  <button type="button" onclick="example4()"><h2>Run example #4</h2></button>
  
</body>
</html>
 
function doSomething() {
  console.log('doSomething(): start');
  return new Promise(function (resolve) {
    setTimeout(function () {
      console.log('doSomething(): end');
      resolve();
    }, 1000);
  });
}
function doSomethingElse() {
  console.log('doSomethingElse(): start');
  return new Promise(function (resolve) {
    setTimeout(function () {
      console.log('doSomethingElse(): end');
      resolve();
    }, 1000);
  });
}
function finalHandler() {
  console.log('finalHandler(): start');
  return new Promise(function (resolve) {
    setTimeout(function () {
      console.log('finalHandler(): end');
      resolve();
    }, 1000);
  });
}
function example1() {
  doSomething().then(function () {
    return doSomethingElse();
  }).then(finalHandler);
}
function example2() {
   doSomething().then(function () {
    doSomethingElse();
  }).then(finalHandler); 
}
function example3() {
  doSomething().then(doSomethingElse())
    .then(finalHandler);
}
function example4() {
  doSomething().then(doSomethingElse)
    .then(finalHandler);
}
Output

You can jump to the latest bin by adding /latest to your URL

Dismiss x
public
Bin info
anonymouspro
0viewers