<script>functionhd(message){returnnewPromise(resolve =>{setTimeout(()=>{resolve(message);},100);});}functiongoal(){return'前端'};functionrun(){let a =hd("俊哥");
console.log(a);let b =hd("学习");
console.log(b);let c =goal()
console.log(c)}run();</script>
改一下代码之后,即可用同步的代码完成异步请求,阻塞执行
<script>functionhd(message){returnnewPromise(resolve =>{setTimeout(()=>{resolve(message);},100);});}functiongoal(){return'前端'};asyncfunctionrun(){let a =awaithd("俊哥");
console.log(a);let b =awaithd("学习");
console.log(b);let c =goal()
console.log(c)}run();</script>