谁是onreadystatechange的的来电时,JavaScript是单线程的?谁是、单线程、onreadystatechange、JavaScript

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

嗯,我是新来的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.

阅读全文

相关推荐

最新文章