Element: customElementRegistry プロパティ
利用可能性は限定的
この機能はベースラインではありません。最も広く使用されているブラウザーの一部で動作しません。
Want more browser support for this feature? Tell us why.
customElementRegistry は Element インターフェイスの読み取り専用プロパティで、この要素に関連付けられた CustomElementRegistry オブジェクトを、設定されていない場合は null を返します。
要素の customElementRegistry は、要素が作成されたときに設定されます(例えば Document.createElement() の使用時に customElementRegistry オプションを指定した場合や、スコープ付きのレジストリーを持つコンテキストで構文解析された場合など)。一度 CustomElementRegistry オブジェクトが設定されると、変更することはできません。このレジストリーは、要素をどのカスタム要素定義を使用してアップグレードするかを決定します。
値
CustomElementRegistry オブジェクト、または null です。
例
>要素のカスタム要素レジストリーへアクセス
この例では、スコープ付きレジストリーをを作成し、それをシャドウルートに接続します。その後、シャドウツリー内の要素から customElementRegistry プロパティを読み取り、それがスコープ付きレジストリーと一致することを確認します。
js
const myRegistry = new CustomElementRegistry();
myRegistry.define(
"my-element",
class extends HTMLElement {
connectedCallback() {
this.textContent = "スコープ付きレジストリーからこんにちは!";
}
},
);
const host = document.createElement("div");
document.body.appendChild(host);
const shadow = host.attachShadow({
mode: "open",
customElementRegistry: myRegistry,
});
shadow.innerHTML = "<my-element></my-element>";
const el = shadow.querySelector("my-element");
console.log(el.customElementRegistry === myRegistry); // true
仕様書
| 仕様書 |
|---|
| DOM> # dom-element-customelementregistry> |