如何将观察到的属性用于匿名类 /函数?
我想在匿名类 /功能上注册自定义元素。但是我想知道如何将观察到的用于对象?
类版本。它的工作原理
<my-el name="abc"></my-el>
class MyEl extends HTMLElement {...}
MyEl.observedAttributes = ["name"];
版本匿名类/函数。它如何不起作用
window.customElements.define("my-el", class extends HTMLElement {...});
// how i can bind now?
MyEl.observedAttributes() // throws an error: ReferenceError: MyEl is not defined
I want to register a custom element with an anonymous class / function. But I wonder how to use the observedAttributes
to the object?
Class Version. How it works
<my-el name="abc"></my-el>
class MyEl extends HTMLElement {...}
MyEl.observedAttributes = ["name"];
Version anonymous class/ function. How it does not work
window.customElements.define("my-el", class extends HTMLElement {...});
// how i can bind now?
MyEl.observedAttributes() // throws an error: ReferenceError: MyEl is not defined
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以定义a static static =“ https://developer.mozilla.org/en-us/docs/web/javascript/reference/reference/functions/get” rel =“ nofollow noreferrer”> getter 在您的类表达式上在ES2015及更高版本中:
否则,如果您可以支持ES2022及以上,则可以创建a 公共静态字段(而不是getter):
You can define a static getter on your class expression like so, which is supported in ES2015 and above:
Otherwise, if you can support ES2022 and above, you can create a public static field (rather than a getter):