JS cannot resolve object


#1

Hi

in HTML I use

<button id="_bt1" type="button" onclick="kt.MyClass.Event.invoke(this)">

for signaling GUI events to Kotlin-JS. That will work for a class like

class MyEvent{
	@JsName("invoke")
    fun invoke(obj: dynamic) {}
}

class MyClass{
    object Event: MyEvent()
}

but moving Event to an e.g. abstract class like

abstract class Control{
    object Event: MyEvent()
}

class OtherClass: Control {
}

the JS runtime crashes with
Uncaught TypeError: Cannot read property ‘invoke’ of undefined
_ at HTMLButtonElement.onclick_

How can I solve this?


#2

Looks like you have declared new type Event and its instance in base abstract class but trying to invoke it from instance of inherited class. There is no OtherClass.Event only Control.Event.
I would recommend using class properties for events, not objects.