我正在尝试转换js:
// var XComponent = document.registerElement('x-component', {
// prototype: Object.create(HTMLElement.prototype, {
// createdCallback: {
// value: function() {
// var root = this.createShadowRoot();
// var template = document.querySelector('#template');
// var clone = document.importNode(template.content, true);
// root.appendChild(clone);
// }
// }
// })
// });
进入scalajs:
import org.scalajs.dom.document
object XComponent {
implicit class ExtendedDom(x: html.Document) {
def registerElement( name:String, obj: js.Object ): Unit = js.native
}
}
class XComponent {
import XComponent._
val xComponent = document.registerElement("x-component", js.Object {
..
})
}
不确定如何处理原型属性..?
答案 0 :(得分:0)
这个怎么样......
import org.scalajs.dom.{document, html}
import scala.scalajs.js
object XComponent {
implicit class ExtendedDom(x: html.Document) {
def registerElement( name:String, obj: js.Object ): Unit = js.native
}
}
class XComponent {
import XComponent._
val xComponent = document.registerElement("x-component", js.Object {
val prototype = js.Object.create(
js.Object{
val createdCallback = js.Object{
def value = {
var root = //this.createShadowRoot();
...
}
}
}
)
})
}