Web组件v1 - 非法构造函数

Bjö*_*rth 6 html javascript web-component custom-element

尝试webcomponents但是我得到了一个错误.

标记很简单,应该可行.2个文件,都是html文件.

错误标记在<script>控制台中的标记上.

谢谢你的帮助.

PS.我正在运行Google Chrome测试版以使customElements正常运行.

KM-button.html

<script>

class KmButton extends HTMLButtonElement {

   constructor() {
     super();
   }

}

customElements.define('km-button', KmButton, {extends: 'button'});

</script>
Run Code Online (Sandbox Code Playgroud)

的index.html

<!DOCTYPE html>
<html>
    <head>
        <!--  import webcomponents  -->
        <link rel="import" href="./components/km-button.html">
    </head>
    <body>
        <km-button>hej</km-button>
    </body>
</html>
Run Code Online (Sandbox Code Playgroud)

错误

km-button.html:1 Uncaught TypeError: Illegal constructor(…)KmButton @ km-button.html:7
Run Code Online (Sandbox Code Playgroud)

Bjö*_*rth 0

是的,当你扩展另一个 DOM 元素时,我似乎错误地<km-button></km-button>使用了它应该使用的标签。<button is="km-button">some text</button>

如果有人犯同样的错误,请留下这个问题。