|
2 | 2 | //
|
3 | 3 | // Type conversions between Go types and JavaScript types are performed automatically according to the following table:
|
4 | 4 | //
|
5 |
| -// | Go types | Go interface type | JavaScript type | |
6 |
| -// | ------------------------------ | ------------------------------ | --------------- | |
7 |
| -// | bool | bool | Boolean | |
8 |
| -// | int?, uint?, float? | float64 | Number | |
9 |
| -// | string | string | String | |
10 |
| -// | [?]int8 | []int8 | Int8Array | |
11 |
| -// | [?]int16 | []int16 | Int16Array | |
12 |
| -// | [?]int32, [?]int | []int | Int32Array | |
13 |
| -// | [?]uint8 | []uint8 | Uint8Array | |
14 |
| -// | [?]uint16 | []uint16 | Uint16Array | |
15 |
| -// | [?]uint32, [?]uint, [?]uintptr | []uint | Uint32Array | |
16 |
| -// | [?]float32 | []float32 | Float32Array | |
17 |
| -// | [?]float64 | []float64 | Float64Array | |
18 |
| -// | all other slices and arrays | []interface{} | Array | |
19 |
| -// | maps, structs | map[string]interface{} | Object | |
20 |
| -// | functions | func(...interface{}) js.Object | Function | |
21 |
| -// | time.Time | time.Time | Date | |
| 5 | +// | Go types | Go interface type | JavaScript type | |
| 6 | +// | ------------------------------ | ----------------- | --------------- | |
| 7 | +// | bool | bool | Boolean | |
| 8 | +// | int?, uint?, float? | float64 | Number | |
| 9 | +// | string | string | String | |
| 10 | +// | [?]int8 | []int8 | Int8Array | |
| 11 | +// | [?]int16 | []int16 | Int16Array | |
| 12 | +// | [?]int32, [?]int | []int | Int32Array | |
| 13 | +// | [?]uint8 | []uint8 | Uint8Array | |
| 14 | +// | [?]uint16 | []uint16 | Uint16Array | |
| 15 | +// | [?]uint32, [?]uint, [?]uintptr | []uint | Uint32Array | |
| 16 | +// | [?]float32 | []float32 | Float32Array | |
| 17 | +// | [?]float64 | []float64 | Float64Array | |
| 18 | +// | all other slices and arrays | js.S | Array | |
| 19 | +// | maps, structs | js.M | Object | |
| 20 | +// | functions | js.F | Function | |
| 21 | +// | time.Time | time.Time | Date | |
22 | 22 | //
|
23 | 23 | // The second column denotes the types that are used when converting to `interface{}`. An exception are DOM elements, those are kept with the js.Object type. Additionally, a pointer to a named type is passed to JavaScript as an object which has wrappers for the type's exported methods. This can be used to provide getter and setter methods for Go fields to JavaScript.
|
24 | 24 | package js
|
@@ -129,14 +129,20 @@ func Keys(o Object) []string {
|
129 | 129 | return s
|
130 | 130 | }
|
131 | 131 |
|
| 132 | +// S is a simple slice type. It is intended as a shorthand for JavaScript arrays (before conversion). |
| 133 | +type S []interface{} |
| 134 | + |
132 | 135 | // M is a simple map type. It is intended as a shorthand for JavaScript objects (before conversion).
|
133 | 136 | type M map[string]interface{}
|
134 | 137 |
|
135 |
| -// S is a simple slice type. It is intended as a shorthand for JavaScript arrays (before conversion). |
136 |
| -type S []interface{} |
| 138 | +// F is a simple func type. |
| 139 | +type F func(...interface{}) Object |
137 | 140 |
|
138 | 141 | func init() {
|
139 |
| - // avoid dead code elimination of Error |
| 142 | + // avoid dead code elimination |
140 | 143 | e := Error{}
|
141 |
| - _ = e |
| 144 | + s := interface{}(S(nil)) |
| 145 | + m := interface{}(M(nil)) |
| 146 | + f := interface{}(F(nil)) |
| 147 | + _, _, _, _ = e, s, m, f |
142 | 148 | }
|
0 commit comments