語法
js
getName(constructor)
引數
constructor-
自定義元素的建構函式。
返回值
先前定義的自定義元素的名稱,如果沒有使用該建構函式定義自定義元素,則返回 null。
示例
js
class MyParagraph extends HTMLElement {
constructor() {
let templateContent = document.getElementById("custom-paragraph").content;
super() // returns element this scope
.attachShadow({ mode: "open" }) // sets AND returns this.shadowRoot
.append(templateContent.cloneNode(true));
}
}
customElements.define("my-paragraph", MyParagraph);
// Return a reference to the my-paragraph constructor
customElements.getName(MyParagraph) === "my-paragraph";
規範
| 規範 |
|---|
| HTML # dom-customelementregistry-getname |
瀏覽器相容性
載入中…