我试图定义一个新的自定义元素扩展HTMLFormElement,如:
class PrintableFormElement extends HTMLFormElement {
constructor() {
super();
console.log("created: ", this);
}
print() { console.log(this.elements)); }
}
customElements.define("printable-form", PrintableFormElement, { extends: "form" });
这不行。 <form is="printable-form" ...>
没有print()
方法(define(...)
似乎失败了),new PrintableFormElement
因Google Chrome 55错误而失败。
new PrintableFormElement
抛出以下错误:
Uncaught TypeError: Illegal constructor
at PrintableFormElement (<anonymous>:3:5)
at <anonymous>:1:1
我不知道如何在当前的谷歌浏览器中定义使用自定义元素v1扩展的自定义元素。
自定义元素v0运行良好,但我想使用它。
答案 0 :(得分:2)
自定义内置元素“v1”尚未在Chrome中实现,您应该使用 polyfill。
有关详细信息,请参阅SO中的此问题: