1 Star 0 Fork 0

Eugene/js-event-loop

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
callback1.html 879 Bytes
一键复制 编辑 原始数据 按行查看 历史
egu0 提交于 2024-04-23 22:54 +08:00 . submit
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Event Loop</title>
</head>
<body>
</body>
<script>
console.log('Hello');
//setTimeout 函数:
// - 创建定时器,由【Web APIs 模块】管理
// - 到达时间后,Web APIs 模块会将回调函数会被放入任务队列
setTimeout(() => console.log('callback1 - timeout=0'), 0);
setTimeout(() => console.log('callback2 - timeout=0'), 0);
console.log('Hi');
// 任务队列:主线程执行完后,从任务队列的头部取任务进行执行
// 具体的就是将任务中的回调函数入栈(调用栈)
/*
执行结果:
----------------------------
Hello
Hi
callback1 - timeout=0
callback2 - timeout=0
*/
</script>
</html>
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/egu0/js-event-loop.git
[email protected]:egu0/js-event-loop.git
egu0
js-event-loop
js-event-loop
master

搜索帮助