DEV Community

Discussion on: Web Component ideas: Building a carousel

Collapse
 
dannyengelman profile image
Danny Engelman • Edited

You can rewrite:

 constructor() {
    super();
    this.attachShadow({mode: 'open'});
    const template = document.getElementById('carousel');
    const clone = template.content.cloneNode(true);
    this.shadowRoot.appendChild(clone);
  }
Enter fullscreen mode Exit fullscreen mode

to:

 constructor() {
    const template = document.getElementById('carousel');
    const clone = template.content.cloneNode(true);
    super()
      .attachShadow({mode: 'open'})
      .append(clone);
  }
Enter fullscreen mode Exit fullscreen mode

Dev.to: 5 more lessons after Web Components 101