how to create JavaScript anonymous object in kotlin? i want to create exactly this object to be passed to nodejs app
var header = {“content-type”:”text/plain” , “content-length” : 50 ...}
how to create JavaScript anonymous object in kotlin? i want to create exactly this object to be passed to nodejs app
var header = {“content-type”:”text/plain” , “content-length” : 50 ...}
Possible solutions:
1) with
js
function:note: the parentheses are mandatory
2) with
dynamic
:3) with
js
+dynamic
:4) with native declaration:
Here's a helper function to initialize an object with a lambda syntax
Usage:
Emited javascript code
One more possible solution:It seems that it does not work anymore with escaped variable names.
I'm a Kotlin newbie (though not a newbie developer), I slightly extended answer from @bashor to something looks neater for keys which are valid Java identifiers, but still allows ones which aren't. I tested it with Kotlin 1.0.1.