Eugenio
05/09/2017, 7:55 PMSomeClass.somemethod()
snrostov
05/09/2017, 7:58 PMfun SomeClass.Companion.somemethod() {
}
Eugenio
05/09/2017, 8:01 PMclass Foo {
companion object {
fun bar() {}
}
}
I want like to do this in JS:
Foo.bar()
but the only possible way seems to be:
Foo.Companion.bar()
because in the output JS the function is on the companion prototypeEugenio
05/09/2017, 8:02 PMsnrostov
05/09/2017, 8:04 PMfun SomeClass.Companion.somemethod()
then I can call it as SomeClass.somemethod
.snrostov
05/09/2017, 8:06 PMclass SomeClass {
companion object
}
fun SomeClass.Companion.somemethod() {
println("hello")
}
fun main(args: Array<String>) {
SomeClass.somemethod()
}
snrostov
05/09/2017, 8:06 PMsomemethod
compiled to
function somemethod($receiver) {
println('hello');
}
snrostov
05/09/2017, 8:08 PMbecause in the output JS the function is on the companion prototypeextension function is compiled to top level functions, and not added to prototype
snrostov
05/09/2017, 8:11 PMsnrostov
05/09/2017, 8:11 PMEugenio
05/09/2017, 8:38 PMEugenio
05/09/2017, 8:38 PM@JvmStatic
in these cases and things will be mapped "natively" static, there should be an equivalent for JS