attachShadow vs createShadowRoot

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

This method is deprecated in favor of attachShadow.

But in my canary: chrome 49.0.2599.0

thats work:

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

And it does not work

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

Does anyone know which right?

+7
source share
1 answer

createShadowRoot() is an old way to bind the shadow-root element to host. This was suggested in the original specification, which was then deprecated in favor of attachShadow . Spec has also been updated .

But the new API has not been standardized and none of the browsers currently support it. Therefore, I would suggest sticking with createShadowRoot . After you start receiving browser warnings for the browser, it will be time to switch to attachShadow .

+14
source

Source: https://habr.com/ru/post/1239127/


All Articles