3 ms·
Let's say I want to use Scala.js to build, not an application, but a JavaScript library. The library exposes a JavaScript API that JavaScript code can call. The
by apo 12y ago
Let's say I want to use Scala.js to build, not an application, but a JavaScript library. The library exposes a JavaScript API that JavaScript code can call. The library's objects can be used in full from JavaScript.
Can I do this with Scala.js? If so, how?
Very few, if no, *-to-JavaScript cross-compilers can do this. For example, Dart might seem to be that language, but on closer inspection, it's not. Your library is locked inside a JavaScript VM-like data structure.
Although you can get a JavaScript object out of Dart-to-JavaScript compiled library, you need to manually hook up every function in its API yourself. In other words, it's not practical to use Dart to build a JavaScript library that exposes a sophisticated JavaScript API.
Is this possible in Scala.js?
- densh 12y agoYes, this is possible. http://www.scala-js.org/doc/export-to-javascript.html http://www.scala-js.org/doc/export-to-javascript.html
- apo 12y agoExactly what I was looking for, thanks!
- euroclydon 12y agoAre you saying that Scala.js ships with a Scala VM in JS, like EMScripten?
- sjrd 12y agoNo, it doesn't. Scala.js is a compiler that emits .js code from your .scala code. There is no layer between the JS VM and that .js code.