in any system that will ever exist, attaching listeners is async. any system that ever uses an event driven style will emit events async. there is no compromise to make there it's a mistake to do so any other way
事件发射应该总是异步的吗?
最佳答案
它应该。
事件发射器只不过是一个大循环,它为给定事件(字符串)调用许多函数。想象一下,一个事件有数千或数十万个绑定(bind)的监听器(函数),我们需要分派(dispatch)该事件类型。如果该分派(dispatch)同步发生,我们将挂起并搞砸我们的整个应用程序,直到所有函数都被调用。由于事件发射器通常与松散耦合的架构并驾齐驱,这将是可怕的。
在这个过程中一定存在某种异步。
关于javascript - 同步发射事件是否不正确?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9526762/