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” ,
It is possible to transform a regular Kotlin object into a JavaScript anonymous object using JavaScript's Object.assign()
. This allows you to stay in pure Kotlin and in type-safety as long as possible. So:
fun Any.toJsObject(): dynamic {
val thisArg = this // Allows use in js() function
return js("Object.assign({},thisArg)")
}
val anObject = object { val a = "a" } // Or use a regular class
console.log( anObject.toJsObject().a ) // logs "a"