Reputation: 126684
I encountered a problem while trying to use Cloud Functions for Firebase with Kotlin.
When accessing data from a database trigger you use the snapshot.val();
function in Javascript. In Kotlin this is not possible because val
is a keyword in Kotlin. I managed a way to go around this by using
snapshot.`val()`
This way I can call functions with any name in Kotlin. Now I think that it is really annoying to type this "grave accent" (`) thingy every time, so I tried to create an extension function.
My problem with that is that I do not know how to reference the type. In Javascript it is DeltaSnapshot
or DataSnapshot
when accessing the database.
How do I extend external classes or how can I call it by a different name? Typealiases won't work because they are limited to classes / instead of supporting functions.
Upvotes: 3
Views: 173
Reputation: 2085
Did you try following?
external class MyClass {
@JsName("val")
fun foo()
}
Upvotes: 3
Reputation: 23515
In javascript a class is an object aswell
snapshot['val']();
More generic
object[functionName]();
object[functionName].call(object, ...args);
object[functionName].apply(object, args);
Upvotes: 1