Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Webcomponents v1 - Illegal constructor

trying out webcomponents but have gotten to a error I dont get.

The markup is simple and should work. 2 files, both are html files.

the error is marked on the <script> tag on in the console.

Thanks for any assistance.

PS. I am running Google Chrome Beta to get the customElements to work.

km-button.html

<script>

class KmButton extends HTMLButtonElement {

   constructor() {
     super();
   }

}

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

</script>

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>

Error

km-button.html:1 Uncaught TypeError: Illegal constructor(…)KmButton @ km-button.html:7
like image 306
Björn Hjorth Avatar asked Sep 21 '16 20:09

Björn Hjorth


1 Answers

Actually it still does't work (after your corrections).

AFAIK the extends feature is not implemented yet in Custom Elements v1 for Chrome.

So the is= syntax is simply (and silently) ignored and your button is viewed as a standard <button>.

like image 133
Supersharp Avatar answered Oct 20 '22 14:10

Supersharp