Why are web workers not allowed to modify the dom

依然范特西╮ 提交于 2019-12-11 03:21:37

问题


I know web workers work as a separate thread than the UI thread but i dont understand why they are not allowed to modify the DOM. I mean that you can allow inter thread communication and keep the DOM data in a shared space and have the web workers thread modify the DOM. Why is this not allowed in browsers?


回答1:


Because the DOM is not threadsafe, and JavaScript does not expose a thread API.


See also:

  • Is JavaScript multithreaded?
  • Thread Safety in Javascript?
  • Using web workers - About thread safety


来源:https://stackoverflow.com/questions/7082190/why-are-web-workers-not-allowed-to-modify-the-dom

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!