Skip welcome & menu and move to editor
Welcome to JS Bin
Load cached copy from
 
<!DOCTYPE html>
<html>
<head>
<script src="https://cdnjs.cloudflare.com/ajax/libs/bluebird/1.2.2/bluebird.js"></script>
  <meta charset="utf-8">
  <title>JS Bin</title>
</head>
<body>
</body>
</html>
 
function double(x) {
  return new Promise((resolve, reject) => {
    setTimeout(() => {
      return resolve(x*2);
    }, 1000);
  });
}
function triple(x) {
  return new Promise((resolve, reject) => {
    setTimeout(() => {
      return resolve(x*3);
    }, 1000);
  });
}
double(2).bind({})
.then(function (result) {
  this.double = result; // store result here
  return triple(2);
})
.then(function (result) {
  console.log('double:', this.double);
  console.log('triple:', result);
  console.log('sum:', this.double + result);
})
.catch((err) => {
  console.log(err.message);
});
Output 300px

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

Dismiss x
public
Bin info
eventhoughpro
0viewers