scala.js和jscala有什么区别? [英] What is the difference between scala.js vs jscala?
问题描述
在JavaScript中有两种工具可以编译Scala代码: Scala.js 和JScala 的。
它们看起来都很棒,可以使用非平凡的Scala代码。
There are two tools to compile Scala code right in the JavaScript: Scala.js and JScala. Both of them look great, and can work with non-trivial Scala code.
它们之间有什么技术差异?
What is the technical difference between them?
推荐答案
实际上有两个以上的工具,但Scala.js和JScala确实是仍在积极开发中的两个工具。
Actually there are more than two tools, but Scala.js and JScala are indeed the 2 tools still under active development.
差别很大:Scala.js是从Scala到JavaScript的编译器,而JScala是一个基于宏的DSL,用于生成JavaScript代码片段。
The difference is fundamental: Scala.js is a compiler from Scala to JavaScript, whereas JScala is a macro-based DSL for generating snippets of JavaScript code.
正如@Gaurav在他的回答中解释的那样,Scala.js是常规的Scala编译器,但它会发出JavaScript代码而不是JVM字节码。您编写的Scala代码永远不会由JVM运行。您的所有Scala代码都已转换为JavaScript。因此,它支持整个Scala语言,包括例如集合库。这对于将整个客户端编写为Scala应用程序非常有用。
As @Gaurav explained in his answer, Scala.js is the regular Scala compiler, but it emits JavaScript code instead of JVM bytecode. The Scala code you write is never run by a JVM. All your Scala code is translated to JavaScript. For that reason, it supports the entire Scala language, including, e.g., the collections library. This is useful to write the entire client-side as a Scala application.
另一方面,使用JScala,大多数应用程序(至少在调用之外的所有应用程序) javascript
macro)仍然在JVM上运行。宏将其中的Scala代码重写为相应的JavaScript AST(或直接作为代码字符串)。这意味着当JVM在那里执行代码时,程序会生成(在运行时)JavaScript AST /字符串。这对于生成要动态发送到客户端的代码片段非常有用。
Using JScala, on the other hand, most of your app (at least everything outside calls to the javascript
macro) is still run on a JVM. The macro rewrites the Scala-looking code inside it to the corresponding JavaScript AST (or directly as a code string). Which means that when the JVM executes the code there, the program generates (at runtime) a JavaScript AST/string. This is useful to generate snippets of code to be sent to the client dynamically.
因此主要的决策标准是:
The main decision criterium is thus:
- 如果您想将Web应用程序的客户端编写为Scala应用程序,请使用Scala.js
- 如果您想生成以下代码段:来自服务器端的JavaScript代码用Scala编写,使用JScala
http://www.sebnozzi.com/84/scala-to-javascript-comparison/
这篇关于scala.js和jscala有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!