什么是事件的Javascript原子执行单元? [英] What is Javascript atomic execution unit for events?

查看:117
本文介绍了什么是事件的Javascript原子执行单元?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

javascript引擎正在执行一个函数,该函数又调用另一个函数(顺序),这样就可以说5s。同时,有几个事件是由用户或以编程方式触发的。

The javascript engine is executing a function which in turn calls another function (sequentially) and this goes on for say 5s. Meanwhile, several events were triggered either by the user or programmatically.

我们可以理所当然地认为在最外层函数完成之前不会处理任何事件吗?

Can we take for granted that no event will be handled before the outermost function finishes?

/* Example */

function outermost_function() {
 function inner_function () {
  function innermost_function () {
    return;
  }
 }
}

推荐答案

Javascript是单线程的,事件在事件循环中排队。 JS代码不在主线程上并行执行。主线程上的代码永远不会中断。

Javascript is single threaded and events are queued in an event loop. JS code does not execute in parallel on the main thread. Code on the main thread is never interrupted.

话虽如此,可以使用网络工作者

关于Javascript事件循环的许多优秀文章,我建议启动这里

There are many excellent articles on the subject of the Javascript event loop, I would recommend starting here

这篇关于什么是事件的Javascript原子执行单元?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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