Anybody knows how to create and use custom events ...
# javascript
h
Anybody knows how to create and use custom events in Kotlin/JS? I'd like to do something like this:
Copy code
class TreeItemSelectEvent<T>(val treeItem: TreeItem<T>) : Event("treeitemselect")

fun select(treeItem: TreeItem<T>) {
    element.dispatchEvent(TreeItemSelectEvent(treeItem))
}
When I try to create and dispatch the event, I get the following error:
Copy code
TypeError: Failed to construct 'Event': Please use the 'new' operator, this DOM object constructor cannot be called as a function.
Using
CustomEvent
instead of
Event
doesn't help. What am I missing?
I've never tried creating my own event class though.
h
Thanks @Robert Jaros Does that mean I have to use
CustomEvent
instead of my own event type which extends from
CustomEvent
?
r
I've tested code very similar to yours and it works fine for me.
oh no, it doesn't
it seems you can't extend
Event
- the compiler generates
Event.call(this, ...);
in JS and doesn't use
new
134 Views