attachShadow vs createShadowRoot

不想你离开。 提交于 2019-12-23 09:10:23

问题


I read in mozilla doc, Element.createShadowRoot() is deprecated:

This method has been deprecated in favor of attachShadow.

But in my canary: chrome 49.0.2599.0

thats work:

 var shadow = document.getElementById("node-sh").createShadowRoot();  

And thats not work

 var shadow = document.getElementById("node-sh").attachShadow({mode: 'closed'});

Anyone know what's right?


回答1:


createShadowRoot() is the old way of attaching a shadow-root to host element. It was proposed in initial spec, which has then been deprecated in favor of attachShadow. Spec also has been updated.

But, new API hasn't been standardized and none of the browsers currently support it. So I would suggest to stick to createShadowRootfor now. Once you start getting browser warnings for deprecation, that would be the time to move to attachShadow.



来源:https://stackoverflow.com/questions/34452028/attachshadow-vs-createshadowroot

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