JavaScript 中的事件处理程序是否以 FIFO、LIFO 或并行方式触发一个事件?

发布于 2024-08-07 05:47:22 字数 52 浏览 1 评论 0原文

JavaScript 中的事件处理程序是否以 FIFO、LIFO 或并行方式触发一个事件?

Does Events Handlers in JavaScript for one event fired as FIFO, LIFO or in parallel?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

深爱不及久伴 2024-08-14 05:47:22

这很简单。 DOM 级别 2 事件模块 不指定事件侦听器的触发顺序。但是,DOM Level 3 事件模块确实指定顺序 与注册相同

首先注册——首先被解雇。

请注意,DOM 级别 3 事件模块仍是草案,而级别 2 模块是推荐。然而,现代浏览器通常遵循这一 3 级规范草案的语义,而不是旧的 2 级规范。

实际上,IIRC,只有 IE 不尊重事件侦听器的顺序。所有其他浏览器都将其实现为 FIFO(如 DOM L3 事件中所述)。您还可以在线找到相关测试 :)

It's very simple. DOM Level 2 Events module does not specify order in which event listeners are to be fired. However, DOM Level 3 Events module does specify order to be the same as registration one.

First registered — first fired.

Note that DOM Level 3 Events module is still a draft, whereas Level 2 one is a recommendation. Nevertheless, modern browsers often follow semantics of exactly this draft Level 3 specification, instead of an older Level 2 one.

In practice, IIRC, only IE doesn't respect order of event listeners. All other browsers implement it as FIFO (and as described in DOM L3 Events). You can also find related tests online :)

私藏温柔 2024-08-14 05:47:22

由于 JavaScript 的单线程特性,事件和计时器会排队并依次执行,它们会在执行中出现空缺时运行。

最好用图表来演示:

Events and Timers

第一个块执行完毕后,有两个异步事件在等待,鼠标点击回调计时器 >,在此示例中,浏览器选择“鼠标单击”,计时器将等待下一个可能的时间,以便执行。

查看 John Resig 撰写的关于 定时器和事件 的非常好的文章。

Due the single threaded nature of JavaScript, events and timers are queued up and executed sequentially one at time, they run when there's been an opening in the execution.

This is best demonstrated with a diagram:

Events and Timers

After the first block finishes its execution, there are two asynchronous events waiting, the Mouse Click Callback and the Timer, the browser picks the Mouse Click in this example, and the timer will wait until the next possible time, in order to execute.

Check this really good article about Timers and Events by John Resig.

为你拒绝所有暧昧 2024-08-14 05:47:22

PPK 在事件冒泡和事件捕获方面有一篇精彩的文章。

http://www.quirksmode.org/js/events_order.html

PPK has an excellent writeup on Event bubbling and Event Capturing.

http://www.quirksmode.org/js/events_order.html

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文