<@U0CJ1V7V3> no state, but we want to keep an exis...
# javascript
e
@yogurtearl no state, but we want to keep an existing API where the functions are called like
SomeClass.somemethod()
s
eugenio: you may use extension function as workaround
Copy code
fun SomeClass.Companion.somemethod() {
    
}
e
@snrostov wait maybe I didn't explain properly; given this:
Copy code
class Foo {
    companion object {
        fun bar() {}
    }
}
I want like to do this in JS:
Copy code
Foo.bar()
but the only possible way seems to be:
Copy code
Foo.Companion.bar()
because in the output JS the function is on the companion prototype
now if I make an extension on the companion, how would that help?
s
hmm, I'm did not test this for js, but for java, if I define
Copy code
fun SomeClass.Companion.somemethod()
then I can call it as
SomeClass.somemethod
.
This is worked for js too:
Copy code
class SomeClass {
    companion object
}

fun SomeClass.Companion.somemethod() {
    println("hello")    
}

fun main(args: Array<String>) {
    SomeClass.somemethod()
}
somemethod
compiled to
Copy code
function somemethod($receiver) {
    println('hello');
  }
because in the output JS the function is on the companion prototype
extension function is compiled to top level functions, and not added to prototype
aah, I'm missed that it should be called from js, not kotlin
sorry
e
yeah, that's the problem 😕
in Java you can just add
@JvmStatic
in these cases and things will be mapped "natively" static, there should be an equivalent for JS