Document: thuộc tính customElementRegistry
Khả dụng hạn chế
This feature is not Baseline because it does not work in some of the most widely-used browsers.
Thuộc tính chỉ đọc customElementRegistry của giao diện Document trả về đối tượng CustomElementRegistry được liên kết với tài liệu này, hoặc null nếu chưa được thiết lập.
Đối với các tài liệu được liên kết với một Window (chẳng hạn như tài liệu chính của một trang), đây là CustomElementRegistry toàn cầu cũng có thể truy cập được thông qua thuộc tính window.customElements. Các tài liệu được tạo theo chương trình (ví dụ: thông qua DOMImplementation.createHTMLDocument()) có custom element registry là null theo mặc định.
Thuộc tính này cũng có sẵn trên các đối tượng ShadowRoot thông qua cùng tên thuộc tính customElementRegistry.
Giá trị
Một đối tượng CustomElementRegistry, hoặc null.
Ví dụ
>Truy cập custom element registry của một tài liệu
Ví dụ này cho thấy customElementRegistry của tài liệu chính giống như registry toàn cầu có sẵn thông qua window.customElements, trong khi các tài liệu được tạo theo chương trình thông qua DOMImplementation.createHTMLDocument() có registry là null theo mặc định.
// The main document's registry is the global one:
console.log(document.customElementRegistry === window.customElements); // true (for Window-associated documents)
// Documents created programmatically have a null registry:
const newDoc = document.implementation.createHTMLDocument("New document");
console.log(newDoc.customElementRegistry); // null
Đặc tả kỹ thuật
| Thông số kỹ thuật |
|---|
| DOM> # dom-documentorshadowroot-customelementregistry> |