-
Notifications
You must be signed in to change notification settings - Fork 573
Closed
Description
o := struct {
*js.Object
a []int `js:"a"`
b js.M `js:"b"`
}{Object: js.Global.Get("Object").New()}
o.a = []int{1}
o.b = js.M{"x": "x"}
fmt.Printf("%v ", o.a[0])
o.a[0] = 2 // <== this doesn't work
fmt.Printf("%v ", o.a[0])
o.Get("a").SetIndex(0, 3) // <== this works but is awkward
fmt.Printf("%v\n", o.a[0])
fmt.Printf("%v ", o.b["x"])
o.b["x"] = "y" // <== this doesn't work either
fmt.Printf("%v ", o.b["x"])
o.Get("b").Set("x", "z") // <== works but awkward
fmt.Printf("%v ", o.b["x"])result:
1 1 3
x x z
Expected:
1 2 3
x y z
As near as I can tell, the array "a" gets $internalize()'ed into a whole new array, which is assigned to and then thrown away. Similarly, "b" gets $internalized()'ed into a whole new object, which is assigned to and then thrown away.
Should one just not put slices or maps in JS objects?
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels