Is there a way to get extension functions to work ...
# javascript
t
Is there a way to get extension functions to work when called from javascript?
Copy code
@JsName("TestClass")
data class TestClass(val num: Int) {
    fun half() = num / 2
}

@JsName("doubleNum")
fun TestClass.doubleNum() = this.num * 2
In the above, I can create instances of TestClass and use the half method, but (perhaps unsurprisingly) the doubleNum() method doesn't exist on the object...
b
Double num is not a member method. It should be on the global scope for you on js side, taking the receiver as an argument
Extension functions in kotlin is just a syntactic sugar, the receiver is always passed as an argument by the compiler
t
yeah, I was hoping the extension function could be added to the prototype. doesn't seem unreasonable in a language like JS