Open
Description
I know now the js tag
works fine, but the struct field has to be accessed directly to be effective, and thus the struct literal
#114 (comment) would not work declaratively, for example:
a := &A{
Object: js.Global.Get("Object").New(),
Method: func() {
println("hello")
},
}
a.Method() // This gives: Uncaught TypeError: a.Object.Method is not a function.
but the following code is ok:
a := &A{
Object: js.Global.Get("Object").New(),
}
a.Method = func() {
println("hello")
}
a.Method() // this is ok
This troubles me for a quite long time, could assignments in struct literal
works directly?
I think this feature is useful and would be friendly to the beginners of gopherjs
, for:
- it's more compatible with
Golang
itself - when using the native js libraries, it's easier to supply constructor options as a
struct literal
than to declare a struct variable first and then to set each field separately - you can be more declarative 😄
Metadata
Metadata
Assignees
Labels
No labels