Tôi đang cố gắng ví dụ từ google developer site và tôi nhận được báo lỗi: "Lỗi Loại:. Constructor bất hợp pháp Có chuyện gì và như thế nào để sửa chữa nóLàm thế nào để tạo ra ví dụ mới của một lớp mở rộng của các yếu tố tùy chỉnh
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;
?
Bạn đang sử dụng trình duyệt (phiên bản nào)? – Bergi
Không có trình duyệt hiện tại nào hỗ trợ [Custom Elements v1] (http://caniuse.com/#feat=custom-elementsv1). –
Từ trang web của nhà phát triển: Chrome 54 (trạng thái) có Phần tử tùy chỉnh v1. Safari đã bắt đầu tạo mẫu và bạn có thể kiểm tra API trong WebKit hàng đêm. Edge đã bắt đầu tạo mẫu. Mozilla có một lỗi mở để thực hiện. – Barmar