March 2019
Beginner to intermediate
324 pages
7h 17m
English
What if we want to expose a Go type with methods to JavaScript?
Let's explore a Go type. The following code has a struct type that represents a musical instrument, and has some getter and setter methods:
type MI struct { MIType string Price float64 Color string Age int}func (mi *MI) SetMIType(s string) { mi.MIType = s}func (mi *MI) GetMIType() string { return mi.MIType}func (mi *MI) SetPrice(f float64) { mi.Price = f}func (mi *MI) GetPrice() float64 { return mi.Price}func (mi *MI) SetColor(c string) { mi.Color = c}func (mi *MI) GetColor() string { return mi.Color}func (mi *MI) SetAge(a int) { mi.Age = a}func (mi *MI) GetAge() int { return mi.Age}
Let's say we want this type to be accessible to JavaScript code. GopherJS comes to ...
Read now
Unlock full access