你知道 Scala 到 Javascript DSL/编译器/其他东西吗?
你知道 Scala 到 Javascript DSL/编译器/其他东西吗? 我想用 Scala 编写 Javascript 代码,这样我就不必编写那么多 JS 代码。 感谢您的帮助!
Do you know a Scala to Javascript DSL/compiler/something?
I want to program my Javascript code with Scala so i dont have to write so much JS code.
Thanks for any help!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
还有 Scala-GWT 项目。
There's also the Scala-GWT project.
您可以尝试 Lift 的 JsCmds 和 JqJsCmds (jquery),看看它能在多大程度上满足您的需求。它在 Lift 应用程序中运行得非常好(还不必回退到原始 javascript)。
You could try out the JsCmds and JqJsCmds (jquery) of Lift to see how far that will support your needs. It works very good in Lift-applications (haven't had to fall back to raw javascript yet).
好吧,你可以将你的scala类反编译为java源代码,然后用GWT编译反编译的java源代码..好吧,但是你应该知道GWT只支持JDK的一个子集..
Well, what you can do decompile your scala class to java source, then compile decompiled java source with GWT.. Well, but you should know that GWT supports only a subset of JDK..
Reactive-web 有一个相当完整、易于阅读的 DSL,用于在 Scala 中编写 Javascript。实际上 DSL 有两个部分:表达式和语句。
语句使用构建器 DSL(在 DSL 中应用对象将实例放在可以收集的线程本地堆栈上)。如果将其包含在
Javascript { ... } 块
中,JavaScript 将在 Lift Web 应用程序中发送到浏览器。如果您只想返回 DSL 对象,请将其括在val (_, theStatements) = JsStatement.inScope{ ... }
中。您可以通过将结果传递给JsStatement.render
将其渲染为String
。以下是测试中的一些代码:
测试中的一些代码
(请注意,虽然当前使用 $,但将来应该将其更改为更具可读性的内容):
Reactive-web has a quite-complete, easy-to-read DSL for writing Javascript in Scala. Actually there are two parts to the DSL: expressions and statements.
Statements use a builder DSL (applying objects in the DSL puts an instance on a thread-local stack which can be collected). If you enclose it in a
Javascript { ... } block
, the javascript will be sent to the browser, in a Lift webapp. If you just want it to return the DSL object, enclose it inval (_, theStatements) = JsStatement.inScope{ ... }
. You can render it to aString
by passing the result toJsStatement.render
.Here's some code from the test:
Expressions
Some code from the tests (note that while it currently uses $, this should be changed in the future to something more readable):
JScala - Scala 宏可将 Scala 代码转换为 JavaScript。
There is JScala - Scala macro that translates Scala code to JavaScript.