|
24 | 24 | // | | false † | false |
|
25 | 25 | // | | new Boolean(false) † | false |
|
26 | 26 | // |---------------------------------+------------------------------------+-----------------------------------------------|
|
27 |
| -// | time.Time | null | time.Time{} | |
28 |
| -// | | undefined | time.Time{} | |
29 |
| -// | | new Date(Date.UTC(2017, 0, 1)) † | time.Date(2017, 1, 1, 0, 0, 0, 0, time.UTC) | |
30 |
| -// |---------------------------------+------------------------------------+-----------------------------------------------| |
31 | 27 | // | int, int8, | null | 0 |
|
32 | 28 | // | int16, int32, | undefined | 0 |
|
33 | 29 | // | int64 | 1 † | 1 |
|
|
43 | 39 | // | | 1 † | 1 |
|
44 | 40 | // | | new Number(1) † | 1 |
|
45 | 41 | // |---------------------------------+------------------------------------+-----------------------------------------------|
|
| 42 | +// | Non *js.Object-special struct | n/a - runtime exception | n/a - runtime exception | |
| 43 | +// | types | | | |
| 44 | +// |---------------------------------+------------------------------------+-----------------------------------------------| |
| 45 | +// | Pointer types (excluding | n/a - runtime exception | n/a - runtime exception | |
| 46 | +// | *js.Object-special struct types | | | |
| 47 | +// | and *js.Object | | | |
| 48 | +// |---------------------------------+------------------------------------+-----------------------------------------------| |
46 | 49 | // | [n]V - array type | null | [n]V{} |
|
47 | 50 | // | length n and | undefined | [n]V{} |
|
48 | 51 | // | element type V | new Array(n) | [n]V{} |
|
49 | 52 | // | | new Array(v1, v2, ... vn) | [n]V{v1, v2, ... vn} |
|
50 | 53 | // | | new TypedArray(n) ‡ | [n]V{} |
|
51 | 54 | // |---------------------------------+------------------------------------+-----------------------------------------------|
|
52 |
| -// | []V - slice type | null | ([]V)(nil) | |
53 |
| -// | element type V | undefined | ([]V)(nil) | |
54 |
| -// | | new Array(n) | ([]V)(nil) | |
| 55 | +// | []V - slice type | null | (nil) | |
| 56 | +// | element type V | undefined | (nil) | |
| 57 | +// | | new Array(n) | (nil) | |
55 | 58 | // | | new Array(v1, v2, ... vn) | [n]V{v1, v2, ... vn} |
|
56 |
| -// | | new TypedArray(n) ‡ | ([]V)(nil) | |
| 59 | +// | | new TypedArray(n) ‡ | (nil) | |
57 | 60 | // |---------------------------------+------------------------------------+-----------------------------------------------|
|
58 |
| -// | map[K]V | null | (map[K]V)(nil) | |
59 |
| -// | | undefined | (map[K]V)(nil) | |
| 61 | +// | map[K]V | null | nil | |
| 62 | +// | | undefined | nil | |
60 | 63 | // | map[string]bool | Object({"1": true}) | map[string]bool{"1": true} |
|
61 | 64 | // | map[interface{}]int | Object({"ok": 5}) | map[interface{}]int{"ok": 5} |
|
62 | 65 | // |---------------------------------+------------------------------------+-----------------------------------------------|
|
63 |
| -// | func(a1 A1, a2 A2, ... an AN) | null | (func type)(nil) | |
64 |
| -// | (r1 R1, r2, R2, ... rn RN) | undefined | (func type)(nil) | |
| 66 | +// | func(a1 A1, a2 A2, ... an AN) | null | nil | |
| 67 | +// | (r1 R1, r2, R2, ... rn RN) | undefined | nil | |
65 | 68 | // | | Any Function | wrapped func val that externalizes args, |
|
66 | 69 | // | | | and internalizes results |
|
67 | 70 | // |---------------------------------+------------------------------------+-----------------------------------------------|
|
|
73 | 76 | // | | | values, the result is a value of type |
|
74 | 77 | // | | | func(vals ...interface{}) *js.Object |
|
75 | 78 | // |---------------------------------+------------------------------------+-----------------------------------------------|
|
| 79 | +// | time.Time | null | time.Time{} | |
| 80 | +// | | undefined | time.Time{} | |
| 81 | +// | | new Date(Date.UTC(2017, 0, 1)) † | time.Date(2017, 1, 1, 0, 0, 0, 0, time.UTC) | |
| 82 | +// |---------------------------------+------------------------------------+-----------------------------------------------| |
76 | 83 | // | *js.Object | Any value | same value - internalization does nothing |
|
77 | 84 | // |---------------------------------+------------------------------------+-----------------------------------------------|
|
78 |
| -// | *js.Object-special struct types | null | new(T) | |
79 |
| -// | *T where T is declared as: | undefined | new(T) | |
| 85 | +// | *js.Object-special struct types | null | nil | |
| 86 | +// | *T where T is declared as: | undefined | nil | |
80 | 87 | // | | Any other value v | &T{o: v} |
|
81 | 88 | // | type T struct { | | |
|
82 | 89 | // | o *js.Object | | |
|
83 | 90 | // | | | |
|
84 | 91 | // | // fields (with js tags) | | |
|
85 | 92 | // | } | | |
|
86 | 93 | // |---------------------------------+------------------------------------+-----------------------------------------------|
|
87 |
| -// | Other struct types | n/a - runtime exception | n/a - runtime exception | |
88 |
| -// |---------------------------------+------------------------------------+-----------------------------------------------| |
89 | 94 | //
|
90 | 95 | // Any source values not listed in this table cause a runtime panic for a given
|
91 | 96 | // target type if a conversion is attempted, e.g. a Javascript number value
|
|
129 | 134 | // |-------------------------------------------+--------------------+---------------------------------------------+-----------+-------------|
|
130 | 135 | // | All numerics types | All valid values | n | number | Number |
|
131 | 136 | // |-------------------------------------------+--------------------+---------------------------------------------+-----------+-------------|
|
132 |
| -// | Slice and array types | All valid values | new Array(v1, v2, ... vn) | object | Array | |
133 |
| -// |-------------------------------------------+--------------------+---------------------------------------------+-----------+-------------| |
134 |
| -// | Map types | All valid values | Object({k1: v2, k2: v2, ... kn: vn}) | object | Object | |
135 |
| -// | | | where k1 is the string value of the | | | |
136 |
| -// | | | externalized source key k1, v1 is the | | | |
137 |
| -// | | | externalized value v1, etc. | | | |
138 |
| -// |-------------------------------------------+--------------------+---------------------------------------------+-----------+-------------| |
139 | 137 | // | Struct values, pointers to struct | All valid values | Object with properties | object | Object |
|
140 | 138 | // | values (excluding *js.Object-special | | set for all exported fields. | | |
|
141 | 139 | // | struct types) | | Property values are externalized | | |
|
142 | 140 | // | | | Go values. | | |
|
143 | 141 | // |-------------------------------------------+--------------------+---------------------------------------------+-----------+-------------|
|
144 | 142 | // | Any type of pointer (excluding *js.Object | All valid values | Externalized result of the value being | * | * |
|
145 | 143 | // | and *js.Object-special struct values) | | pointed to | | |
|
146 |
| -// | | | | | | |
147 |
| -// | | | | | | |
148 | 144 | // |-------------------------------------------+--------------------+---------------------------------------------+-----------+-------------|
|
149 |
| -// | time.Time, *time.Time | All valid values | Corresponding Date value | object | Date | |
| 145 | +// | Slice and array types | All valid values | new Array(v1, v2, ... vn) | object | Array | |
| 146 | +// |-------------------------------------------+--------------------+---------------------------------------------+-----------+-------------| |
| 147 | +// | Map types | All valid values | Object({k1: v2, k2: v2, ... kn: vn}) | object | Object | |
| 148 | +// | | | where k1 is the Javascript String value of | | | |
| 149 | +// | | | the externalized source key k1, v1 is the | | | |
| 150 | +// | | | externalized value v1, etc. | | | |
150 | 151 | // |-------------------------------------------+--------------------+---------------------------------------------+-----------+-------------|
|
151 | 152 | // | func(a1 A1, a2 A2, ... an AN) | nil | undefined | undefined | n/a |
|
152 | 153 | // | (r1 R1, r2, R2, ... rn RN) | Non-nil value | Function value that wraps the Go func, | function | Function |
|
153 | 154 | // | | | internalizes args and externalizes results | | |
|
154 | 155 | // |-------------------------------------------+--------------------+---------------------------------------------+-----------+-------------|
|
155 | 156 | // | Any interface value | All valid values | Externalized result of the underlying value | * | * |
|
156 | 157 | // |-------------------------------------------+--------------------+---------------------------------------------+-----------+-------------|
|
| 158 | +// | time.Time | All valid values | Corresponding Date value | object | Date | |
| 159 | +// |-------------------------------------------+--------------------+---------------------------------------------+-----------+-------------| |
157 | 160 | // | *js.Object | Any value | Same value - externalization does nothing | * | * |
|
158 | 161 | // |-------------------------------------------+--------------------+---------------------------------------------+-----------+-------------|
|
159 | 162 | // | *js.Object-special struct types | All valid values v | v.o | * | * |
|
|
176 | 179 | // † - Source values annotated with † are generally applicable to all valid
|
177 | 180 | // values of the target type. e.g. for target type string, "ok" represents
|
178 | 181 | // all valid string primitive values.
|
| 182 | +// |
179 | 183 | package js
|
180 | 184 |
|
181 | 185 | // Object is a container for a native JavaScript object. Calls to its methods are treated specially by GopherJS and translated directly to their JavaScript syntax. A nil pointer to Object is equal to JavaScript's "null". Object can not be used as a map key.
|
|
0 commit comments