|
9 | 9 | // When values pass from Javascript to Go, a process known as internalization,
|
10 | 10 | // the following conversion table is applied:
|
11 | 11 | //
|
12 |
| -// |----------------+-------------------------+---------------+--------| |
13 |
| -// | Go target type | Javascript source value | Translation | Result | |
14 |
| -// |----------------+-------------------------+---------------+--------| |
15 |
| -// | string | null | UTF16 -> UTF8 | "" | |
16 |
| -// | | undefined | | "" | |
17 |
| -// | | "" | | "" | |
18 |
| -// | | new String("") | | "" | |
19 |
| -// | | "ok" † | | "ok" | |
20 |
| -// | | new String("ok") † | | "ok" | |
21 |
| -// |----------------+-------------------------+---------------+--------| |
22 |
| -// | bool | null | none | false | |
23 |
| -// | | undefined | | false | |
24 |
| -// | | false † | | false | |
25 |
| -// | | new Boolean(false) † | | false | |
26 |
| -// |----------------+-------------------------+---------------+--------| |
| 12 | +// |----------------+---------------+-------------------------+--------| |
| 13 | +// | Go target type | Translation | Javascript source value | Result | |
| 14 | +// |----------------+---------------+-------------------------+--------| |
| 15 | +// | string | UTF16 -> UTF8 | null | "" | |
| 16 | +// | | | undefined | "" | |
| 17 | +// | | | "" | "" | |
| 18 | +// | | | new String("") | "" | |
| 19 | +// | | | "ok" † | "ok" | |
| 20 | +// | | | new String("ok") † | "ok" | |
| 21 | +// |----------------+---------------+-------------------------+--------| |
| 22 | +// | bool | none | null | false | |
| 23 | +// | | | undefined | false | |
| 24 | +// | | | false † | false | |
| 25 | +// | | | new Boolean(false) † | false | |
| 26 | +// |----------------+---------------+-------------------------+--------| |
27 | 27 | //
|
28 | 28 | // Any source values not listed in this table cause a runtime panic for a given
|
29 | 29 | // target type if a conversion is attempted, e.g. a Javascript number value
|
30 | 30 | // being assigned to a string type Go variable.
|
31 | 31 | //
|
32 | 32 | // Source values annotated with † are generally applicable to all valid
|
33 | 33 | // values of the target type. e.g. for target type string, "ok" represents
|
34 |
| -// all valid string values. |
| 34 | +// all valid string primitive values. |
35 | 35 | //
|
36 | 36 | // Externalization
|
37 | 37 | //
|
38 | 38 | // When values pass from Go to Javascript, a process known as externalization,
|
39 | 39 | // the following conversion table is applied:
|
40 | 40 | //
|
41 |
| -// To follow |
| 41 | +// |----------------+---------------+-----------------+--------+---------+-------------| |
| 42 | +// | Go source type | Translation | Go source value | Result | typeof | constructor | |
| 43 | +// |----------------+---------------+-----------------+--------+---------+-------------| |
| 44 | +// | string | UTF8 -> UTF16 | "" | "" | string | String | |
| 45 | +// | | | "ok" † | "ok" | | | |
| 46 | +// |----------------+---------------+-----------------+--------+---------+-------------| |
| 47 | +// | bool | none | false | false | boolean | Boolean | |
| 48 | +// | | | true | true | | | |
| 49 | +// |----------------+---------------+-----------------+--------+---------+-------------| |
| 50 | +// |
| 51 | +// Source values annotated with † are generally applicable to all valid |
| 52 | +// values of the target type. e.g. for target type string, "ok" represents |
| 53 | +// all valid string values. |
| 54 | +// |
| 55 | +// Special struct types |
42 | 56 | //
|
43 |
| -// Additionally, for a struct containing a *js.Object field, only the content |
44 |
| -// of the field will be passed to JavaScript and vice versa. |
| 57 | +// To follow.... |
45 | 58 | package js
|
46 | 59 |
|
47 | 60 | // 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