CustomElementRegistry: getName() method
Limited availability
This feature is not Baseline because it does not work in some of the most widely-used browsers.
Phương thức getName() của giao diện CustomElementRegistry trả về tên cho một custom element đã được định nghĩa trước đó.
Cú pháp
js
getName(constructor)
Tham số
constructor-
Constructor cho custom element.
Giá trị trả về
Tên của custom element đã được định nghĩa trước đó, hoặc null nếu không có custom element nào được định nghĩa với constructor đó.
Ví dụ
js
class MyParagraph extends HTMLElement {
constructor() {
const template = document.getElementById("custom-paragraph");
super() // returns element this scope
.attachShadow({ mode: "open" }) // sets AND returns this.shadowRoot
.append(document.importNode(template.content, true));
}
}
customElements.define("my-paragraph", MyParagraph);
// Return a reference to the my-paragraph constructor
customElements.getName(MyParagraph) === "my-paragraph";
Thông số kỹ thuật
| Specification |
|---|
| HTML> # dom-customelementregistry-getname> |