我的问题是关于为自定义元素扩展HTMLElement。
class Foo extends HTMLElement { ... }
class Bar extends Foo { ... }
class FooBar extends Bar { ... }
每个人都在构造函数中调用super()。
当我使用Bar定义自定义元素时,不会出现任何错误
customElements.define( 'custom-tag', Bar );
or
customElements.define( 'custom-tag', class Bar extends Foo { ... } );
我正在尝试使用FooBar类定义自定义元素。
customElements.define( 'other-custom-tag', FooBar );
or
customElements.define( 'other-custom-tag', class FooBar extends Bar { ... } );
但是我得到
Uncaught TypeError: Failed to execute 'define' on 'CustomElementRegistry':
The provided value cannot be converted to a sequence.
通过Mozilla文档
https://developer.mozilla.org/en-US/docs/Web/API/CustomElementRegistry/define
TypeError The referenced constructor is not a constructor.
我找不到与此问题有关的任何东西...
答案 0 :(得分:0)
问题很可能是 static get observedAttributes()
- 就我而言,我有一个愚蠢的错字,在数组上使用 push
返回新数组元素的 count而不是数组本身(用 concat
代替,就像一个魅力)。
换句话说,只要确保静态 getter 返回一个数组就可以了 ?