Note: this is a very rough sketch of a proposal to serve as a reference in other issues, more design work is required to make it fully practical.
Proposal
- If a user type implements
Externalizer interface, GopherJS will use the result of Externalize() method when exporting this object to JavaScript. Otherwise standard conversion rules are applied.
- If a user type implements
Internalizer interface, GopherJS will create a new Go type instance and call Internalize() method on it, passing the original *js.Object in, and will use the instance as internalized value.
package js
type Externalizer interface {
Externalize() *js.Object
}
type Internalizer interface {
Internalize(o *js.Object)
}
The general idea is similar to that if Marshaler/Unmarshaler interfaces in package/json.
Motivation