I put details in <#C0B8MA7FA|getting-started>
# javascript
j
I put details in #getting-started
g
Could you show some better example, it’s hard to understand what do you want to achieve from your example in getting-started
j
That class is defined in a package I depend on. In my usage of that class I have need to extend it.
I simply want to do fun ContextMenusNamespace.create() but that doesn't seem to compile
g
An extension function should compile just fine. Looking at what you have in #getting-started, you can do
fun ContextMenusNamespace.create(){ your code here...}
Realize that the way an extension function works is by creating a standalone function and then passing the instance of the class it is called on as the first parameter of the function, so the class has to be instantiated first before an extension function can work, same as any other method on a class. You can also just extend the class by declaring the external class as
open
🙌 1
j
Thanks Graham, that was exactly what I kept bumping up against, I didn’t quite realize I needed to instantiate the new class. I wound up having to redefine Window because I couldn’t find getSelection() on it.
Copy code
external abstract class MyWindow : Window {
    fun getSelection() : Node?
}
external val window: MyWindow
This works for me now. Cheers.
g
Why not just:
Copy code
fun Window.getSelection(): Node? = asDynamic().getSelection()
It’s even more clear. Because extend existing class make sense only if you want to instantiate that class yourself. Also, no problem with name clash between your
window
and
kotlin.browser.window
j
that’s much better, i was trying to get that to work originally but i think i was trying to tac external on the front and that was giving met he error i kept running into.