I have a question on namespaces/naming/etc. Say I ...
# javascript
v
I have a question on namespaces/naming/etc. Say I have a js module
moduleName
Copy code
module.exports = {
    foo:  { /* some code here */ },
    C:  { /* some code here */ }
}
I can import it to kotlin like this:
Copy code
@file:JsModule("moduleName")
package ext.jspackage.name

external fun foo()

external class C
The problem with this is that if I want to use that functionality elsewhere in kotlin code - I’ll have to import the functions/objects directly. I.e. like
import ext.jspackage.name.foo
. Which is not great, as that name can be generic/etc. What I want is to recreate experience where I’d call the
foo
function with module name prefix -
moduleName.foo()
I can’t import modules in Kotlin though, and
external
things can’t be defined within non external ones, so I can’t do something like
Copy code
object moduleName {
    external fun foo()
}
Is there a way to accomplish this?
s
Use
@JsModule
on external object:
Copy code
@JsModule("moduleName")
external object moduleName  {
    fun foo()
}
❤️ 1
Also, you don’t have to import packages. You can use
foo
from your snippet as
ext.jspackage.name.foo()
v
ah, nice, I somehow missed that you can do something like that (re option 1)
thanks!