Skip welcome & menu and move to editor
Welcome to JS Bin
Load cached copy from
 
<!DOCTYPE html>
<html>
<head>
<meta name="description" content="This bin is an example of calling async methods with a callback x number of times in a loop">
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width">
  <title>JS Bin</title>
</head>
<body>
</body>
</html>
 
function add(x, y) {
  return new Promise (function(resolve, reject) {
    resolve (x + y);
  });
}
function subtract(x, y ) {
  return new Promise (function(resolve, reject) {
    resolve(x - y);
  });
}
var x = 1,
    y = 2;
add(x, y)
.then(function (result) {
  return subtract(result, x);
})
.then(function (result) {
  return add(result, y);
})
.then(function (result) {
  return subtract(result, y);
})
.then(function (result) {
  return add(result, x);
})
.then(function (result) {
  return console.log(result);
});
console.log("before or after?");
Output 300px

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

Dismiss x
public
Bin info
jlaustillpro
0viewers