Is it possible to create an element if you have its constructor but don't know its tag name?
Example:
class CustomElement extends HTMLElement {}
customElements.define(genRandomString(), CustomElement);
Is it possible to create a new instance of CustomElement
? Or can you obtain its tag name in any way?
I'm asking this because I'm not sure what's the correct way to pass custom elements to functions that need them: do I need to pass around both the name and the constructor, in case one may need to either create an element (which requires the name) or to check whether an existing element is of this kind (which requires the constructor)?
Is it possible to create an element if you have its constructor but don't know its tag name?
If you have access to the constructor (like you said you have), you can just use
const instance = new CustomElement();
Please note that this might fail if the constructor
doesn't conform to Custom Element constructor constraints.