``` val myMap = mutableMapOf<String, String>...
# javascript
j
Copy code
val myMap = mutableMapOf<String, String>()
myMap["content-type"] = "application/json"
myMap["content-length"] = "50"

myMap.toPlainJSObject()//Put your transform logic here
b
joris: feel free to submit an issue 🙂
j
Oh, it wasn't meant as an issue, think @aimozg has more insights in what a proper solution might be
a
well I'm using
Copy code
inline fun jsobject(init: dynamic.(jso:dynamic) -> Unit): dynamic {
	return (Object()).apply {init(this,this)}
}
inline fun<T> jsobject2(init: T.() -> Unit): T {
	return (Object().asDynamic() as T).apply(init)
}
the first one is for fully free-form objects
Copy code
fun save() = jsobject {
		it.name = name
		it.defVal = defVal.save()
		it.minVal = minVal.save()
		it.maxVal = maxVal.save()
	}
the second is when you have an interface to do static checks against:
Copy code
external interface JSTreeNodeInit {
	var text: String
	var id: String?
	var icon: String?
	var parent: String?
	var children: Array<JSTreeNodeInit>?
}
fun treeNodeSelf(): JSTreeNodeInit = jsobject2 {
		id = "ModelPart_$id"
		text = "'$name' ($classname)"
	}
Javascript object is accessible in
jsobject
both as
this
(as in http://stackoverflow.com/a/36307953/1113090) and as
it
which I feel more secure with
b
I think we can have more than one solutions.
Also we could have intrinsic for the case
mapOf(“aaa” to “bbb”).toPlainJSObject()
and generate
{‘aaa’ : ‘bbb'}