Skip welcome & menu and move to editor
Welcome to JS Bin
Load cached copy from
 
<!DOCTYPE html>
<html>
<head>
<meta charset=utf-8 />
<title>Async queue</title>
</head>
<body>
  <p>see the console...</p>
</body>
</html>
 
// CLICK PREVIEW!
Queue = [];
Queue.execute = function () {
  if (Queue.length)
    Queue.shift()(Queue.execute);
  else 
    Queue.last();
};
Queue.last = function() {
  console.log("end");
};
    
Queue.push(function(callback){
  console.log("1");
  callback();
});
  
Queue.push(function(callback){
  console.log("2");
  callback();
});
  
Queue.push(function(callback){
  console.log("3");
  callback();
});
  
Queue.push(function(callback){
  console.log("4");
  callback();
});
  
Queue.execute();
Output

This bin was created anonymously and its free preview time has expired (learn why). — Get a free unrestricted account

Dismiss x
public
Bin info
anonymouspro
0viewers