--- title: CustomElementRegistry.get() slug: Web/API/CustomElementRegistry/get tags: - CustomElementRegistry - Experimental - Web Components - custom elements translation_of: Web/API/CustomElementRegistry/get ---
{{APIRef("CustomElementRegistry")}}
{{domxref("CustomElementRegistry")}} 的get()
方法返回以前定义自定义元素的构造函数.
constructor = customElements.get(name);
指定名字的自定义元素的构造函数,如果没有使用该名称的自定义元素定义,则为undefined
。
customElements.define('my-paragraph',
class extends HTMLElement {
constructor() {
super();
let template = document.getElementById('my-paragraph');
let templateContent = template.content;
const shadowRoot = this.attachShadow({mode: 'open'})
.appendChild(templateContent.cloneNode(true));
}
})
// Return a reference to the my-paragraph constructor
Specification | Status | Comment |
---|---|---|
{{SpecName("HTML WHATWG", "custom-elements.html#dom-customelementregistry-get", "customElements.get()")}} | {{Spec2("HTML WHATWG")}} | Initial definition. |
{{Compat("api.CustomElementRegistry.get")}}