JavaScript Encapsulation with WebComponents/ShadowDOM

亡梦爱人 提交于 2019-12-22 08:16:53

问题


Probably simple question, that I haven't really found an answer for:

Does ShadowDOM or WebComponents (as the bigger Standard) actually encapsulate JavaScript aswell? Like having seperate namespaces for each component?

From what I encountered with Polymer that wasn't the case yet, which is obvious, given that polymer is doing it's polyfilling through JS.

Thanks!


回答1:


The Shadow DOM and Custom Element specs say nothing about script encapsulation. The only thing that SD gives you is <style> encapsulation and event retargeting (events look like they come from the host element and not internal elements. For custom elements, you can do tricks to namespace your JS (e.g. anonymous self calling functions, wrapping the constructor in a namespace, etc.)



来源:https://stackoverflow.com/questions/18976643/javascript-encapsulation-with-webcomponents-shadowdom

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