javascript内部:如何实现事件? [英] javascript internals: how events are implemented?

查看:134
本文介绍了javascript内部:如何实现事件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的问题是关于JS引擎如何实现异步事件的模式,当我们在dom上做一些绑定事件处理程序,让我们说一个点击事件?

My question is related to how the JS engines implement the pattern of asynchronous events when we do something like bind event handlers on a dom for lets say a click event.?

他们是否有类似一个单独的线程正在监听所有的点击事件?当一个事件确实发生时,它们是否引用绑定列表并引发事件?

Do they have something like a separate thread that is listening to all the click events ? When an event does occur , do they refer the bind list and bubble up the events ?

类似于Ajax,异步网络调用,浏览器跨越一个新线程这将开始监听来自服务器的数据,当接收到响应时,它会调用成功处理程序?

Similar is with Ajax,the asynchronous network call, where the browser spans a new thread that would start listening to the data from the server and when the response is received, it would call the success handler?

推荐答案

读取关于javascript事件的这篇文章排队,看看是否回答你的大部分问题。将有一个本机OS线程处理与实际OS事件(鼠标事件,键盘事件,定时器事件,网络I / O事件等)的接口,然后将它们馈送到JS引擎可以进一步扩展的JS队列中将它们发送到Javascript代码。在OS级别有多少个独立的线程是实现具体的,可能会随实施而变化。

Read this post about the javascript event queue and see if it answers most of your question. There will be a native OS thread that handles interfacing with actual OS events (mouse events, keyboard events, timer events, network I/O events, etc...) and those are then fed into the JS queue where the JS engine can further dispatch them to Javascript code. How many separate threads there are at the OS level is implementation specific and likely does vary with the implementation.

这篇关于javascript内部:如何实现事件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆