简体   繁体   English

Scala.js导出抽象val / var

[英]Scala.js exporting abstract val/var

It seems that exporting abstract val/var with descendants like this doesn't work: 像这样导出带有后代的抽象val / var似乎不起作用:

@JSExportDescendentObjects
trait T {
  @JSExport
  val i: Int
  @JSExport
  var j: Int
}

class A extends T {
  val i = 5
  var j = 10
}

I get warnings no valid targets for annotation on value i - it is discarded unused and A 's i and j are not seen from Javascript. 我收到警告, no valid targets for annotation on value i - it is discarded unused ,并且从Javascript中看不到Aij However, it is possible to export them via @JSExportAll : 但是,可以通过@JSExportAll导出它们:

@JSExportDescendentObjects
@JSExportAll
trait T {
  val i: Int
  var j: Int
}

class A extends T {
  val i = 5
  var j = 10
}

It is fine now, no warnings and i and j are visible from JS. 现在很好,没有警告,并且从JS中可以看到ij

def s doesn't have such problem. def s没有这个问题。 Why is this and how can I selectively export abstract val/var? 为什么会这样,如何选择导出抽象val / var?

This was a bug in Scala.js <= 0.6.10. 这是Scala.js <= 0.6.10中的错误 Upgrading to Scala.js 0.6.11 should fix your problem. 升级到Scala.js 0.6.11应该可以解决您的问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM