--- title: CustomElementRegistry slug: Web/API/CustomElementRegistry tags: - API - CustomElementRegistry - Experimental - Interface - Reference - Web Components translation_of: Web/API/CustomElementRegistry --- <div>{{DefaultAPISidebar("Web Components")}}</div> <p><span class="seoSummary"><strong><code>CustomElementRegistry</code></strong> 인터페이스는 사용자 지정 요소를 등록하고, 등록한 요소를 가져올 수 있는 메서드를 제공합니다.</span> 인스턴스에 접근하려면 {{domxref("window.customElements")}} 속성을 사용하세요.</p> <h2 id="메서드">메서드</h2> <dl> <dt>{{domxref("CustomElementRegistry.define()")}}</dt> <dd>새로운 <a href="/ko/docs/Web/Web_Components/Custom_Elements">사용자 지정 요소</a>를 정의합니다.</dd> <dt>{{domxref("CustomElementRegistry.get()")}}</dt> <dd>유명 사용자 지정 요소의 생성자를 반환합니다. 그런 요소가 없는 경우 {{jsxref("undefined")}}를 대신 반환합니다.</dd> <dt>{{domxref("CustomElementRegistry.upgrade()")}}</dt> <dd>사용자 지정 요소가 자신의 섀도 루트(shadow root)에 연결되기 전에 직접 업그레이드합니다.</dd> <dt>{{domxref("CustomElementRegistry.whenDefined()")}}</dt> <dd>주어진 이름의 사용자 지정 요소가 등록되는 순간 이행하는, 빈 {{jsxref("Promise")}}를 반환합니다. 만약 그런 요소가 이미 등록된 경우 즉시 이행합니다.</dd> </dl> <h2 id="예제">예제</h2> <p>다음 코드는 <a href="https://github.com/mdn/web-components-examples/tree/master/word-count-web-component">word-count-web-component</a> 예제에서 가져온 것입니다(<a href="https://mdn.github.io/web-components-examples/word-count-web-component/">라이브로 확인하세요</a>). 사용자 지정 요소 클래스를 생성한 후, {{domxref("CustomElementRegistry.define()")}} 메서드로 등록하는 과정을 살펴보세요.</p> <pre class="brush: js">// Create a class for the element class WordCount extends HTMLParagraphElement { constructor() { // Always call super first in constructor super(); // count words in element's parent element var wcParent = this.parentNode; function countWords(node){ var text = node.innerText || node.textContent return text.split(/\s+/g).length; } var count = 'Words: ' + countWords(wcParent); // Create a shadow root var shadow = this.attachShadow({mode: 'open'}); // Create text node and add word count to it var text = document.createElement('span'); text.textContent = count; // Append it to the shadow root shadow.appendChild(text); // Update count when element content changes setInterval(function() { var count = 'Words: ' + countWords(wcParent); text.textContent = count; }, 200) } } // Define the new element customElements.define('word-count', WordCount, { extends: 'p' });</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#customelementregistry", "CustomElementRegistry")}}</td> <td>{{Spec2("HTML WHATWG")}}</td> <td>Initial definition.</td> </tr> </tbody> </table> <h2 id="브라우저_호환성">브라우저 호환성</h2> <p>{{Compat("api.CustomElementRegistry")}}</p>