I need a function that maps JavaScript builtin class to corresponding html tag name, e.g.:
function classToTagName(clazz) {
// implementation
}
classToTagName(HTMLInputElement) // ->
"input"
classToTagName(HTMLAnchorElement) // ->
"a"
Is it possible to implement it without using explicit mapping or regex?
I could use DOM tagName
property if I had object instance, but browsers seem to prohibit invoking constructors of builtin tag classes with TypeError: Illegal constructor
.
According to Custom Elements,
When defining our custom element, we have to also specify the extends option:
customElements.define("plastic-button", PlasticButton, { extends: "button" });
The spec editors already know that may seem redundant information, but they explain:
In general, the name of the element being extended cannot be determined simply by looking at what element interface it extends, as many elements share the same interface (such as
q
andblockquote
both sharingHTMLQuoteElement
).
So it's not possible. Your mapping is not well-defined.
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