对于下面的 JavaScript 代码,我该如何用 ReasonML 编写它?
class HelloWorld extends HTMLElement {
constructor() {
super();
// Attach a shadow root to the element.
let shadowRoot = this.attachShadow({mode: 'open'});
shadowRoot.innerHTML = `<p>hello world</p>`;
}
}
我找不到任何关于在 ReasonML 中编写类的文档?我不能使用普通对象/类型,因为我需要从不适用于ES 样式类的 HTMLElement 类进行扩展。
我已经研究了这个现有的问题 - How to extend JS class in ReasonML然而,这是另一回事。要编写 Web 组件,我们需要扩展HTMLElement
并且必须使用new
关键字调用它。ES5 样式扩展机制不起作用。