Open
Description
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 ofExternalize()
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 callInternalize()
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
- Interoperability with JavaScript BigInt libraries: U/Int64 conversion #360.
- Importing configuration objects from JavaScript: Enable a way to pass/access a JSON object from backend to frontend more efficiently (skipping unmarshaling from a string). #359.