Following the js-modules reference page I was able...
# javascript
m
Following the js-modules reference page I was able to declare the function
getInfo
from module
ytdl-core
. I have some problems when calling it but I'd like to ask you another question. I don't want to pollute the global namespace with module-specific function, so I used this syntax to declare the whole module and its function(s).
Copy code
@JsModule("ytdl-core")
external class Ytdl {
    companion object {       
        fun getInfo(name: String, options : dynamic, callback : (dynamic, dynamic) -> Unit) : Unit
    }
}
Now I can read all javascript properties of
Ytdl
with
Object.getOwnPropertyNames()
(and
getInfo
in among them) but I don't know how to refer to `Ytdl.getInfo`: both
Object.getOwnPropertyNames(Ytdl.getInfo)
and
Object.getOwnPropertyNames(Ytdl::getInfo)
fail to compile. The first is assumed to be a function call (lacking its arguments), the second causes a "Unresolved reference: getInfo". Am I missing something?
b
@melatonina could you show generated code for second?
why do you like call getOwnPropertyNames on this function?
k
Why not
external object Ytdl
?
👍 1
Why do you want to get reference to
getInfo
?
You can write
Ytdl.Companion::getInfo
m
Yes, declaring an
external object Ytdl
was more appropriate. Sorry for all these questions that may appear to be silly to you. It's still not clear when I should use
external class
and when I should use
external object
. I'll re-read that page.
I was trying to call
getOwnPropertyNames
on that function because when I was calling, it wasn't behaving as it was supposed to do. Now it seems to be working fine.