Skip welcome & menu and move to editor
Welcome to JS Bin
Load cached copy from
 
<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width">
  <title>JS Bin</title>
</head>
<body>
</body>
</html>
 
function resolveAfter5Seconds(para) { 
  let d = new Date();
  console.log('當前秒數:' + d.getSeconds());
  return new Promise(resolve => {
    setTimeout(() => {
      if(para == 20) {
        console.log('秒數:' + d.getSeconds() + '輸出 Y了!');  
      } else {
        console.log('秒數:' + d.getSeconds() + '輸出 X了!');
      }
      resolve(para);
    }, 5000);
  });
}
async function f1() {
  //這邊的await順序,可以理解 await的操作模式
  let y = await resolveAfter5Seconds(20);
  let x = await resolveAfter5Seconds(10);
  console.log(x); // 10
  console.log(y); // 20
}
f1();
Output 300px

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