Promise封装一秒后打印Hello World

 

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>
<body>
<script>

const printSomething = arg => new Promise((resolve, reject) => {
  setTimeout(() => {
    console.log(‘printSomething: ‘, arg)
    resolve(arg)
  }, 1000)
})

function printOtherThing(arg) {
  return new Promise((resolve, reject) => {
    setTimeout(() => {
      console.log(‘printOtherThing: ‘, arg)
      resolve(arg)
    }, 1000)
  })
}

printSomething(‘Hello World‘).then(response => {
  console.log(‘printSomething response: ‘, response)
})

printOtherThing(‘Hello Promise‘).then(response => {
  console.log(‘printOtherThing response: ‘, response)
})

</script>
</body>
</html>

 

Promise封装一秒后打印Hello World

上一篇:编译-词法语法分析


下一篇:蓝牙连接