JavaScript 中的事件执行
比如说,JavaScript 正在执行某个方法,我按下了一个附加了一些事件处理程序的按钮。当前方法执行会暂停并立即开始执行单击事件处理程序,还是js会完成方法执行然后才继续执行单击事件处理程序?
Say, JavaScript is in the middle of executing some method, and I'm pressing a button which has some event handler attached. Will the current method execution get paused and the click event handler start executing right away, or will js finish method execution and only then proceed with executing the click event handler?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
由于 Javascript 是单线程的,因此该事件将在当前 Javascript 执行完成后触发。这也是您的浏览器可能锁定的原因。
The event will fire after the current Javascript finishes execution, since Javascript is single threaded. This is also why your browser can lock up.
当前正在执行的代码将继续运行,直到返回,然后下一个事件将从事件队列中运行。很可能是您的鼠标单击事件。
The currently executing code will continue running until it has returned and then the next event will be run out of the event queue. Will be most likely your mouse click event.