Changes enums
Enums#
In Go, enums are often defined as a type and a set of constants. For example:
Due to incompatibility between Go and JavaScript, custom types cannot be used in this way. The best strategy is to use a type alias for float64:
In Javascript, you can then use the following:
- Why use
float64
? Can't we useint
?- Because JavaScript doesn't have a concept of
int
. Everything is anumber
, which translates tofloat64
in Go. There are also restrictions on casting types in Go's reflection package, which means usingint
doesn't work.
- Because JavaScript doesn't have a concept of