语法
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 |
浏览器兼容性
加载中…