Is there a faster way to create a js object yet, o...
# javascript
s
Is there a faster way to create a js object yet, or is
js("{}")
and then manually populating it with data still the most convenient?
c
Copy code
val obj: dynamic = object{}
    reducers.forEach { obj[it.key] = it.value}
This is how I do it, but I have no clue about the difference in speed..
k
You can use the
json()
function
for example
Copy code
json(
        "tooltip" to json(
                "trigger" to "axis"
        ),
        "xAxis" to json(
                "data" to xAxisData
        )
)
s
That looks super expensive. I see 6 short lived objects created from that
I mean super expensive in comparison to doing it natively. Does the compiler optimize those object creations away?
g
just do js("{}") and make an external interface so you can cast it and use it like a normal object
if your worried about optimization that is probably the quickest, but i doubt if either of the other two methods mentioned will have any noticeable impact on speed.
👍 1