0%

仅作笔记用:JS 一行代码实现同步的延时语句

就是这一句代码

1
await new Promise(resolve => setTimeout(resolve, 2000));

最后的数字就是延时时长

示例

1
2
3
4
5
(async function() {
console.log("延时开始");
await new Promise(resolve => setTimeout(resolve, 2000));
console.log("延时结束");
})();

效果

Buy me a coffee
No.5972 Alipay

Alipay