SOURCE

console 命令行工具 X clear

                    
>
console
const app = document.getElementById('app');
// app.style.background = 'red';
function sleep(duration) {
  return new Promise(resolve => {
    setTimeout(resolve, duration);
  })
}
function changeColor(duration, color) {
  return new Promise(resolve => {
    app.style.background = color;
    sleep(duration).then(resolve);
  })
}
function main() {
  return new Promise(resolve => {
    changeColor(3000, 'red').then(() => {
      changeColor(2000, 'yellow').then(() => {
        changeColor(1000, 'green').then(() => {
          main();
        })
      })
    })
  })
}
main()
<div id="app"></div>
#app{
    width: 100px;
    height: 100px;
    background: white;
}