Document: customElementRegistry プロパティ
利用可能性は限定的
この機能はベースラインではありません。最も広く使用されているブラウザーの一部で動作しません。
Want more browser support for this feature? Tell us why.
customElementRegistry は Document インターフェイスの読み取り専用プロパティで、この文書に関連付けられた CustomElementRegistry オブジェクトを、設定されていない場合は null を返します。
Window に関連付けられた文書(ページのメイン文書など)の場合、これはグローバルな CustomElementRegistry であり、window.customElements プロパティからもアクセス可能です。プログラムによって作成された文書(例えば DOMImplementation.createHTMLDocument() を使用した場合など)では、デフォルトでカスタム要素レジストリーは null になります。
このプロパティは、ShadowRoot オブジェクト上でも、同時に customElementRegistry というプロパティ名を通じて利用可能です。
値
CustomElementRegistry オブジェクト、または null です。
例
>文書のカスタム要素レジストリーへアクセス
この例は、メイン文書の customElementRegistry が window.customElements で利用できるグローバルレジストリーと同じものである一方、DOMImplementation.createHTMLDocument() を用いてプログラムで作成された文書では、デフォルトでレジストリーが null になることを示しています。
js
// メイン文書のレジストリーはグローバルなもの
console.log(document.customElementRegistry === window.customElements); // true (ウィンドウに関連付けられた文書)
// プログラムによって作成された文書では、レジストリーが null になります。
const newDoc = document.implementation.createHTMLDocument("New document");
console.log(newDoc.customElementRegistry); // null
仕様書
| 仕様書 |
|---|
| DOM> # dom-documentorshadowroot-customelementregistry> |