Hi - I have an imported npm library whose API for ...
# webassembly
d
Hi - I have an imported npm library whose API for JavaScript is to create an object from a function located in another object, in JS it would be like this
const myNewInstance = new library.ctorFunction(...)
. How can I define this in Kotlin WASM with
external
? The closest I gotten to is:
Copy code
external interface Library {
  fun ctorFunction(...): JsAny
}
But the glue created does not contain the
new
keyword, it is simply:
'org.dany.test.ctorFunction_$external_fun' : (_this, p0, p1, p2) => _this.ctorFunction(p0, p1, p2)
and without the
new
the type check of the external function throws a NPE. It seems the JavaScript glue will only emit a
new
keyword if its a Kotlin external class with a constructor, say
@JsName("ctorFunction") external class LibInstance constructor(...)
but now I have lost passing the JS object containing the constructor function. The glue code is simply
new ctorFunction(...)
where as I need
new _this.ctorFunction(...)
like if it was a member external function. Additionally external extension functions are not supported right now. Any idea on how to do this? Thanks!
r
Perhaps try something similar to this with
js()
function: https://pl.kotl.in/8EKPJYxpj
👍 1
d
That worked! Thaaank you so much! I had no idea you could reference param via their names from
js()
.