window屬性:customElements

2018-04-03 10:25 更新

customElements屬性

該 Window 接口的 customElements 只讀屬性用于返回對該 CustomElementRegistry 對象的引用,該對象可用于注冊新的自定義元素并獲取有關(guān)以前注冊的自定義元素的信息。

customElements屬性語法

let customElementRegistry = window.customElements;

customElements屬性返回值

customElements 屬性返回一個 CustomElementRegistry 對象實(shí)例,表示當(dāng)前窗口的自定義元素注冊表。

customElements屬性示例

你會看到使用這個屬性的最常見的例子是訪問 CustomElementRegistry.define() 方法來定義和注冊一個新的自定義元素,例如:

let customElementRegistry = window.customElements;
customElementRegistry.define('my-custom-element', MyCustomElement);

但是,它通常縮寫為以下內(nèi)容:

customElements.define('element-details',
  class extends HTMLElement {
    constructor() {
      super();
      const template = document
        .getElementById('element-details-template')
        .content;
      const shadowRoot = this.attachShadow({mode: 'open'})
        .appendChild(template.cloneNode(true));
  }
});

規(guī)范

規(guī)范狀態(tài)注釋
HTML Living Standard
規(guī)范中的'window.customElements'的定義。
Living Standard
初始定義。

瀏覽器兼容性

我們正在將兼容性數(shù)據(jù)轉(zhuǎn)換為機(jī)器可讀的JSON格式。

  • 電腦端
特征Firefox(Gecko)
Chrome
Edge
Internet Explorer
Opera
Safari
window.customElements不支持支持不支持??
  • 移動端

特征Firefox Mobile (Gecko)Chrome for AndroidIE MobileOpera MobileSafari Mobile
window.customElements?????
以上內(nèi)容是否對您有幫助:
在線筆記
App下載
App下載

掃描二維碼

下載編程獅App

公眾號
微信公眾號

編程獅公眾號