Robert Jaros
08/19/2020, 12:57 PMinline fun <reified T> Any?.createInstance(vararg args: dynamic): T {
val jsClass = this
val argsArray = (listOf<dynamic>(null) + args).toTypedArray()
return js("new (Function.prototype.bind.apply(jsClass, argsArray))").unsafeCast<T>()
}
like this:
external interface Ext
val constructor: Any = require("...").something // returns a function which should be called with new operator in JS
val ext: Ext = constructor.createInstance(it)
It doesn't work with IR anymore. How can I replace this?diesieben07
08/19/2020, 1:14 PMdiesieben07
08/19/2020, 1:22 PMRobert Jaros
08/19/2020, 1:25 PMjs()
blockRobert Jaros
08/19/2020, 1:25 PMvar jsClass_1_4 = tmp0_createInstance_0_2;
var tmp0_toTypedArray_0_3_6 = plus_1(listOf_1(null), tmp1_createInstance_0_3);
var argsArray_2_5 = copyToArray_0(tmp0_toTypedArray_0_3_6);
var tmp1_unsafeCast_0_4_7 = new (Function.prototype.bind.apply(jsClass, argsArray))();
diesieben07
08/19/2020, 1:26 PMjsClass
variable to something elsediesieben07
08/19/2020, 1:27 PMjsClass
propertyRobert Jaros
08/19/2020, 1:29 PMdiesieben07
08/19/2020, 1:30 PMdiesieben07
08/19/2020, 1:40 PMinline
from the function and the mangling goes awayRobert Jaros
08/19/2020, 2:10 PM