未捕获的TypeError:扩展HTMLButtonElement时的非法构造函数

时间:2017-02-08 17:25:29

标签: javascript custom-element

我有来自here的以下课程:

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());
    }
}

当它被实例化时,我收到错误:

fancy-button.js:5 Uncaught TypeError: Illegal constructor

当我点击该位置时,我提出了这个:

((e) => { throw e; })

类构造函数有什么问题?

0 个答案:

没有答案