0

I use many calls like this in the HTML page to call my Scala.js code:

<table
  id="history"
  onclick="my.domain.project.name.ObjectName().handlerFunction(event.target)"
>

<script type="text/javascript">
  my.domain.project.name.ObjectName().otherFunction()
</script>

Is there some way to avoid typing the package name again and again, something like Scala / Java imports? I want to keep the package names in my Scala sources because I cross compile them for JVM as well and do not want to encounter package conflicts there.

Suma
  • 33,181
  • 16
  • 123
  • 191

1 Answers1

2

There are two solutions. The first one is a bit similar to a Scala import, and is done in JavaScript:

var ObjectName = my.domain.project.name.ObjectName;
ObjectName().otherFunction();

The other is to export ObjectName specifically with a shorter name, which is done in Scala.js:

package my.domain.project.name

import scala.scalajs.js.annotation._

@JSExport("ObjectName")
object ObjectName { ... }

then in JavaScript:

ObjectName().otherFunction();
sjrd
  • 21,805
  • 2
  • 61
  • 91