addEventListener的回调函数在Event Loop中的宏任务队列中排队?
我知道setTimeout
、setInterval
、setImmediate
api的回调函数是在宏任务队列中排队的。
但是,我不确定 addEventListener
。
addEventListener的回调函数是否在宏任务队列中排队?
请检查:D
I know that the callback function of setTimeout
, setInterval
, setImmediate
api is queued in macro task queue.
But, I'm not sure about addEventListener
.
Is the callback function of addEventListener is queued in macro task queue?
Check please :D
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
它不是。在计时器任务队列中排队的是一个任务。此任务的步骤将负责执行回调(通过触发事件算法)。回调本身存储在内存中。
对于事件侦听器来说,情况大致相同,事件回调永远不会在任务源中排队,只有任务或微任务才会排队,并且作为这些任务步骤的一部分,将分派事件并执行回调。
例如,您很可能从微任务中触发事件(例如 slotchange 事件,但您也可以使用
EventTarget#dispatchEvent()
自行强制执行),大多数本机事件通常是任务的一部分(只需搜索短语触发事件
在 HTML 规范中示例),并且您有大量事件不会从任何任务或微任务触发,而是直接作为事件循环处理的一部分,在 更新渲染 步骤。It's not. What is queued in the timer task-queue is a task. This task's steps will be responsible of executing the callbacks (through the fire an event algo). The callback itself is stored in memory.
For event listeners it's about the same, event callbacks are never queued in a task source, only tasks or microtasks are, and as part of these tasks's steps the events are dispatched and the callbacks are executed.
For instance you can very well have an event fire from a microtask (e.g the slotchange event, but you can also force it yourself with
EventTarget#dispatchEvent()
), most native events are generally part of task (just search for the phraseto fire an event
in the HTML specs for examples), and you have loads of events that don't fire from any tasks nor microtask, but directly as part of the event loop processing, in the update the rendering step.