浏览器仍然获取某些内容时,全局执行上下文是否会脱离调用堆栈?

我有这样的代码块:

function printData(response) {
  response.json()
          .then(data => console.log(data.name));
}

const fetchedData = fetch("http://localhost:3000/url");

fetchedData.then(printData);

console.log("First console output");

This code executes directly whenever the page loads. My endpoint fetch("http://localhost:3000/url") returns response after 200ms.

Since the XHR will resolve after all global execution context finishes, it should get out of the call stack. But does global execution really gets out of the call stack? Because there is still a task to process, still we need to run printData function after request resolves. Will global execution context wait until request resolves or does it get out of the call stack even there are some requests still being fetched?

流是这样的;

  1. printData设置为内存
  2. 将fetchedData变量设置为内存,并且xhr会启动浏览器功能
  3. 请求。
  4. 将printData分配给fetchedData promise。
  5. 控制台输出。

Now global execution context finishes but still, we are waiting for the response of the fetch("http://localhost:3000/url");. Will the global execution context get out of the call stack or will it wait the request to fulfill?

评论