HTMLElement (and it's descendants, such as HTMLDivElement, HTMLSpanElement etc) are defined as interfaces according to the MDN documentation.
If I wanted to implement these interfaces with TypeScript, I can do the following.
class CustomElement implements HTMLElement {
// implementation
}
However implementing interfaces in TypeScript doesn't generate any code, so it's difficult to see how to achieve interface implementation with pure JavaScript.
How should these interfaces be implemented with pure JavaScript?
jsFiddle Demo
You would use the prototype of HTMLElement
var CustomElement = function(){};
CustomElement.prototype = HTMLElement.prototype;
And now you can construct them using the new keyword
var myElement = new CustomElement();
//myElement will now have access to the HTMLElement prototype
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With