2016-09-13 29 views
4

我在玩v1 web組件。據埃裏克Bidelman在Custom elements v1: reusable web components,一V1 Web組件可以定義與創造:爲什麼v1 web組件customElements.define()拋出TypeError

class App extends HTMLElement { 

    attachedCallback() { 
    this.attachShadow({mode: 'open'}); 
    this.shadowRoot.innterHTML = `<div>web component</div>` 

    } 
} 

<x-app></x-app> 

然而,在Chrome Canary版的最新版本,並與V1運行代碼時在Firefox中填充工具,下面的錯誤被拋出:

Uncaught TypeError: Failed to construct 'HTMLElement': Please use the 'new' operator, this DOM object constructor cannot be called as a function. 
+0

ES5考慮自定義元素:https://github.com/w3c/webcomponents/issues/423 –

回答

4

如果您transpile ES6代碼,你將需要包括來自webcomponents本地-shim.js代碼/ src目錄/銅stomElements/Vs以上。

+0

嘿那裏..這對舊版瀏覽器如何工作?看起來你不應該將native-shim.js轉換爲ES5,所以我不確定這是如何工作的,比如iOS 8本身不支持ES6或自定義元素。 – Prefix

相關問題