DEV Community

Discussion on: [tutorial] How to create a Web Component?

Collapse
 
dannyengelman profile image
Danny Engelman
constructor(){
    super();
    this.attachShadow({mode: 'open'});
    this.shadowRoot.appendChild(template.content.cloneNode(true));
}
Enter fullscreen mode Exit fullscreen mode

can all be chained,
and append is shorter... you don't use appendChilds return value

constructor(){
    super() // sets AND returns 'this'
     .attachShadow({mode: 'open'}) // sets AND returns this.shadowRoot
     .append(template.content.cloneNode(true));
}
Enter fullscreen mode Exit fullscreen mode

source: Web Components 102