Search code examples
javascriptkotlinkotlin-interopkotlin-js-interop

How to access Kotlin object from JavaScript


I'm using kotlin2js to generate JS library from Kotlin code. I'm then using this library in Javascript (not Kotlin). The code has some Kotlin objects and some normal classes. I can access normal classes from Javascript, but I can't access the objects in any way.

The documentation is pretty sparse, only relevant line might be this:

Kotlin preserves lazy object initialization in JavaScript.

I'm not sure what that means.


Solution

  • The problem was that Kotlin changed name of the method to something like this: calculate_ywek2$(). And it's very hard to figure out, because Kotlin doesn't generate Typescript definitions, so autocomplete doesn't work. The name can be changed with @JsName annotation.