为什么不允许网络工作者修改dom [英] Why are web workers not allowed to modify the dom

查看:54
本文介绍了为什么不允许网络工作者修改dom的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道 web worker 是独立于 UI线程的线程,但是我不明白为什么不允许他们修改 DOM .我的意思是,您可以允许线程间通信并将 DOM 数据保留在共享空间中,并让 web worker 线程修改 DOM .为什么浏览器不允许这样做?

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?

推荐答案

因为DOM不是线程安全的,并且JavaScript不会公开线程API.

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

另请参阅:

这篇关于为什么不允许网络工作者修改dom的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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