Próbuję przykład z google developer site i dostaję błąd: „TypeError. Nielegalnym konstruktora Co się stało i jak to naprawićJak utworzyć nową instancję dłuższy klasy elementów niestandardowych
class FancyButton extends HTMLButtonElement {
constructor() {
super(); // always call super() first in the ctor.
this.addEventListener('click', e => this.drawRipple(e.offsetX,e.offsetY));
}
// Material design ripple animation.
drawRipple(x, y) {
let div = document.createElement('div');
div.classList.add('ripple');
this.appendChild(div);
// div.style.top = `${y - div.clientHeight/2}px`;
// div.style.left = `${x - div.clientWidth/2}px`;
div.style.backgroundColor = 'currentColor';
div.classList.add('run');
div.addEventListener('transitionend', e => div.remove());
}
}
customElements.define('fancy-button', FancyButton, {extends: 'button'});
let button = new FancyButton();
button.textContent = 'Fancy button!';
button.disabled = true;
?
Jakiej przeglądarki (wersji) używasz? – Bergi
Żadna z obecnych przeglądarek nie obsługuje [Elementy niestandardowe v1] (http://caniuse.com/#feat=custom-elementsv1). –
Ze strony dla programistów: Chrome 54 (status) ma elementy niestandardowe v1. Safari zaczęło prototypować i możesz przetestować API w nocnym programie WebKit. Edge rozpoczął prototypowanie. Mozilla ma otwarty błąd do wdrożenia. – Barmar