用Kotlin编写javascript应用程序 [英] Writing javascript applications with Kotlin
问题描述
我最近开始研究Kotlin,并设法创建了我的第一个JVM应用程序.拥有可以同时编译为Java和JS的单一语言真是太酷了.因此,现在我开始使用Kotlin2js并尝试了解Javascript的互操作性,以及使用jQuery之类的JS框架的可能性.
I recently started to have a look at Kotlin and managed to create my first JVM applications. It's so cool to have a single language that compiles both to Java and JS. So, now I started playing with Kotlin2js and tried to understand the Javascript interoperability, and the possibilities to use JS frameworks like jQuery.
我找到了两个博客文章和示例: http://blog.jetbrains.com/kotlin/2013/10/在浏览器中编写kotlin/ http://blog.jetbrains.com/kotlin/2014/12/javascript-互操作/ https://github.com/JetBrains/kotlin/blob/master/libraries/tools/kotlin-gradle-plugin/src/test/resources/testProject/kotlin2JsProject/mainProject/src /main/kotlin/example/main.kt
I found a couple of blog posts and examples: http://blog.jetbrains.com/kotlin/2013/10/writing-kotlin-in-the-browser/ http://blog.jetbrains.com/kotlin/2014/12/javascript-interop/ https://github.com/JetBrains/kotlin/blob/master/libraries/tools/kotlin-gradle-plugin/src/test/resources/testProject/kotlin2JsProject/mainProject/src/main/kotlin/example/main.kt
是否有Kotlin JS库的文档? http://kotlinlang.org/api/latest/jvm/stdlib/index.html
我首先编译了一个简单的示例应用程序,该应用程序将import kotlin.browser.*
与gradle用作构建系统(最终并与
I first compiled a simple sample app which used import kotlin.browser.*
with gradle as build system which (finally and with some help here worked, thanks again!). Than I imported the project into IDEA and suddenly it didn't compile anymore, I had to change the import to import js.dom.html.*
. So, I guess it uses a different version of library? (And IDEA added apply plugin: 'kotlin'
to my build.gradle in addition to kotlin2js and I guess this doesn't work.)
IDEA将kotlin-jslib.jar复制到lib,该清单的清单中显示为"Implementation-Version:0.7.270".对于gradle的编译,我使用了kotlin 1.0.1-1,并且我很确定我在创建项目时也在IDEA中选择了该版本.
IDEA copied kotlin-jslib.jar to lib which says it's "Implementation-Version: 0.7.270" in its Manifest. For the compilation with gradle I used kotlin 1.0.1-1 and I'm pretty sure that I also selected this version in IDEA when creating the project.
那么,了解Kotlin2js和Kotlin-js-lib的最佳信息来源是什么?
特别是Javascript的互操作性,如何使用jQuery之类的框架(似乎在kotlin-js-lib中提供了jQuery支持),但是,我又该如何使用尚未获得Kotlin支持的其他框架.我了解Kotlin具有dynamic
关键字和 http://blog. jetbrains.com/kotlin/2014/12/javascript-interop/提到了noImpl,当我尝试使用它时会导致编译错误.
也许目前最好的方法是查看Kotlin的资源?
So, what are the best sources of information to understand Kotlin2js and the Kotlin-js-lib?
Especially the Javascript interoperability, how to use Frameworks like jQuery (it seems that there is jQuery support in the kotlin-js-lib), but also, how I can use other frameworks that don't come with Kotlin support yet. I understood that Kotlin has the dynamic
keyword, and http://blog.jetbrains.com/kotlin/2014/12/javascript-interop/ mentioned noImpl which lead to a compile error when I tried to use it.
Maybe the best way for now is to look at the Kotlin sources?
嗯,这是一个相当长的,没有结构的问题,涉及多个方面,但这是我目前学习Kotlin的状态:-)也许其他人也遇到相同的问题.
Well, this is a rather long and unstructured question covering several aspects, but that's my current state of learning Kotlin :-) And maybe others experience the same problem.
推荐答案
与此同时,Kotlin/JS在1.2版中可用,并且有一个教程和参考网站.
Meanwhile Kotlin/JS is available in version 1.2 and there is an introduction, tutorial and reference on the official website.
这篇关于用Kotlin编写javascript应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!