Calling JavaScript from Kotlin
Calling JavaScript from Kotlin
Kotlin was designed for easy interoperation with Java platform. It sees Java classes as Kotlin classes, and Java sees Kotlin classes as Java classes. However, JavaScript is a dynamically-typed language, which means it does not check types in compile-time. You can freely talk to JavaScript from Kotlin via dynamic types, but if you want the full power of Kotlin type system, you can create Kotlin headers for JavaScript libraries.
Inline JavaScript
You can inline some JavaScript code into your Kotlin code using the js("…") function. For example:
fun jsTypeOf(o: Any): String { return js("typeof o") }
The parameter of js
is required to be a string constant. So, the following code is incorr