How can I access an `object` from Javascript`? Kot...
# javascript
f
How can I access an
object
from Javascript`? Kotlin:
Copy code
package foo.bar

object Obj {
    fun func() = 2
}
JS:
Copy code
var x = foo.bar.Obj.func() // Invalid!
s
Try accessing it using name of generated module:
moduleId.foo.bar.Obj.func()
f
Actually originally I did have my module but it failed, I tried adding the module in this example and it works. Odd.. thanks though
Ah, the problem occurs when the function is an extension method: Kotlin:
Copy code
package foo.bar

object Obj {
}

fun Obj.func() = 2
JS:
Copy code
var x = module.foo.bar.Obj.func() // Invalid!
s
Try
Copy code
package foo.bar

object Obj {
}

@JsName("func")
fun Obj.func() = 2
JS:
Copy code
module.foo.bar.func()
f
That works, thanks!
👍 2