hallvard
01/18/2019, 9:41 PM@JvmOverloads
, usable from java both with and without its single String parameter. I can't make it work in js. The hello
function in the example here: https://kotlinlang.org/docs/reference/js-to-kotlin-interop.html#jsname-annotation doesn't have greeting
as an optional parameter. So are optional parameters not possible for a js target (without using the external
modifier and actually writing the js yourself)?thana
01/19/2019, 12:24 PMkotlinJs
will generate some if statements into the single generated hello
funktion to determine whether the optional parameter is given or notSvyatoslav Kuzmich [JB]
01/19/2019, 1:06 PM@JsName("hello")
fun hello(greeting: String = "Hello") {
println("$greeting!")
}
This will be compiled down to:
function hello(greeting) {
if (greeting === void 0)
greeting = 'Hello';
println(greeting + '!');
}
Then you can call it from JS with or without argument:
hello();
hello("Привет");
hallvard
01/19/2019, 4:05 PM