【发布时间】:2018-09-27 00:42:36
【问题描述】:
我的问题是关于为自定义元素扩展 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.
我找不到与此问题相关的任何内容...
【问题讨论】:
-
customElements.define会抛出哪个错误? “不能转换为序列”还是“不是构造函数?” -
"无法转成序列"
-
我高度怀疑这是由于您的自定义元素的实现细节造成的错误。您可以发布一个可以重现错误的课程吗?
-
我正在尝试重现该错误。我认为它来自静态 getobservedAttributes 方法。
-
你能提供更多与你的类相关的代码吗?你的构造函数是什么样的?
标签: javascript class custom-element