Note that named exports don't support overloading. Therefore the
following will fail:
class A {
@JSExportNamed
def a(foo: Int) = foo + 1
@JSExportNamed
def a(bar: String) = "Hello " + bar
}
As of Scala.js 0.6.11, @JSExportNamed is deprecated without direct
replacement (see https://github.com/scala-js/scala-js/issues/2442).
You should take a single parameter of a JS type and decompose it yourself.
For example, instead of
class A {
@JSExportNamed
def foo(a: Int, b: String, c: Boolean = false): Unit = {
// do something with a, b, c
}
}
you should write:
trait FooOptions extends js.Object {
val a: Intval b: Stringval c: js.UndefOr[Boolean]
}
class A {
@JSExport
def foo(options: FooOptions): Unit = {
val a = options.a
val b = options.b
val c = options.c.getOrElse(false)
// do something with a, b, c
}
}
Exports the given method to JavaScript with named parameters.
It can then be called like this:
Note that named exports don't support overloading. Therefore the following will fail:
As of Scala.js 0.6.11,
@JSExportNamed
is deprecated without direct replacement (see https://github.com/scala-js/scala-js/issues/2442). You should take a single parameter of a JS type and decompose it yourself. For example, instead ofyou should write:
(Since version 0.6.11)
Export Scala.js APIs to JavaScript