谁是onreadystatechange的的来电时,JavaScript是单线程的? [英] Who is the caller of onreadystatechange when javascript is single-threaded?

查看:107
本文介绍了谁是onreadystatechange的的来电时,JavaScript是单线程的?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗯,我是新来的JavaScript和听到它是单线程的。在我的脑海里,如果你做一个异步请求,就应该启动一个自己的线程控制,如果服务器已经响应。这将不会在Javascript工作。我想有一些既节约了所有的听众,并呼吁他们,根据他们同意的条件内置机制(onreadystatechange的)。

Well, i am new to javascript and heard it is single-threaded. In my mind if you make an asynchronous request, it should start an own thread which controls if the server already responded. This won't work in Javascript. I am thinking is there some built-in mechanism which saves all listeners and calls them, depending on conditions they have "agreed" to (onreadystatechange).

这只是一个假设,我想我是完全错误的。好吧,也许有人可以帮助我在这里?

This is just an assumption and I guess i am totally wrong. Well, maybe somebody can help me here?

推荐答案

只有JavaScript执行本身是单线程的,按如下说明 。然而,底层引擎可能会使用多个线程。

Only the javascript execution itself is single-threaded, as explained here. Yet, the underlying engine might use more threads.

那么,HTTP请求(在浏览器中的大便产生的地方深)可能有自己的线程,但是当事情(如响应)发生时,它会触发一个事件排队,到JS任务调度。一旦当前脚本的执行已经结束,的onreadystatechange 函数将被调用。

So, the HTTP request (created somewhere deep in the bowels of the browser) might have its own thread, but when something (like a response) happens, it will fire an event to be queued into the JS task scheduler. As soon as the current script execution has ended, the onreadystatechange function will be called.

这篇关于谁是onreadystatechange的的来电时,JavaScript是单线程的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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