--- title: CustomElementRegistry.get() slug: Web/API/CustomElementRegistry/get tags: - CustomElementRegistry - Experimental - Web Components - custom elements translation_of: Web/API/CustomElementRegistry/get --- <p>{{APIRef("CustomElementRegistry")}}</p> <p><span class="seoSummary"> {{domxref("CustomElementRegistry")}} 的<code><strong>get()</strong></code>方法返回以前定义自定义元素的构造函数.</span></p> <h2 id="语法">语法</h2> <pre class="syntaxbox"><em>constructor</em> = customElements.get(<em>name</em>); </pre> <h3 id="参数">参数</h3> <dl> <dt>name</dt> <dd>你想要返回引用的构造函数的自定义元素的名字。</dd> </dl> <h3 id="返回值">返回值</h3> <p>指定名字的自定义元素的构造函数,如果没有使用该名称的自定义元素定义,则为<code>undefined</code>。</p> <h2 id="例子">例子</h2> <pre class="brush: js">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 <span class="message-body-wrapper"><span class="message-flex-body"><span class="devtools-monospace message-body">let ctor = customElements.get('my-paragraph');</span></span></span> </pre> <h2 id="规范">规范</h2> <table class="standard-table"> <tbody> <tr> <th scope="col">Specification</th> <th scope="col">Status</th> <th scope="col">Comment</th> </tr> <tr> <td>{{SpecName("HTML WHATWG", "custom-elements.html#dom-customelementregistry-get", "customElements.get()")}}</td> <td>{{Spec2("HTML WHATWG")}}</td> <td>Initial definition.</td> </tr> </tbody> </table> <h2 id="浏览器兼容性">浏览器兼容性</h2> <div> <p>{{Compat("api.CustomElementRegistry.get")}}</p> </div>