I am trying to create a custom Web Component that extends the HTMLTableElement class. The code is relatively simple:
class DataTable extends HTMLTableElement {
constructor() {
super();
this.data = JSON.parse(decodeURIComponent(this.getAttribute(data)));
const head = this.createTHead();
}
}
customElements.define('data-table', DataTable, {extends:'table'});
The error comes when I try to call createTHead(). According to documentation, this is a function of HTMLTableElement (which my class extends) and returns an HTMLTableSectionElement object. However, I get an error as stated in the title: createTHead called on an object that does not implement interface HTMLTableElement
I am expecting the HTMLTableSectionElement to be created, instead I get the error. I have tried to remove the options from the define call, and I get an "Illegal Constructor" error.
Reproducible: https://jsfiddle.net/nw3rsjtv/