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” ,
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.
@JsName("Object")
open class Object {
}
fun jsobject(init: dynamic.() -> Unit): dynamic {
return Object().apply(init)
}
header = jsobject {
validJavaIdentifier = 0.2
this["content-type"] = "text/plain"
this["content-length"] = 50
}