You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Add extra information about ES modules inside the js-interop document (#4932)
* Add extra information about ES modules inside the js-interop document
* chore: apply community suggestions on clarifying the module systems that expose package structure
* update: js-interop review
* chore: add links to module systems
---------
Co-authored-by: alepedroza <[email protected]>
Copy file name to clipboardExpand all lines: docs/topics/js/js-to-kotlin-interop.md
+22-10Lines changed: 22 additions & 10 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -14,46 +14,58 @@ all declarations are available to JavaScript via the `myModule` object. For exam
14
14
funfoo() ="Hello"
15
15
```
16
16
17
-
Can be called from JavaScript like this:
17
+
This function can be called from JavaScript like this:
18
18
19
19
```javascript
20
20
alert(myModule.foo());
21
21
```
22
22
23
-
This is not applicable when you compile your Kotlin module to JavaScript modules like UMD (which is the default setting
24
-
for both `browser` and `nodejs` targets), CommonJS or AMD. In this case, your declarations will be exposed in the format
25
-
specified by your chosen JavaScript module system. When using UMD or CommonJS, for example, your call site could look
23
+
Calling the function directly like this is not applicable when you compile your Kotlin module to JavaScript modules like [UMD](https://github.com/umdjs/umd) (the default setting
24
+
for both `browser` and `nodejs` targets), [ESM](https://tc39.es/ecma262/#sec-modules), [CommonJS](https://nodejs.org/api/modules.html#modules-commonjs-modules), or [AMD](https://github.com/amdjs/amdjs-api/wiki/AMD).
25
+
In these cases, your declarations are exposed according to the chosen JavaScript module system.
26
+
For example, when using UMD, ESM, or CommonJS, your call site would look
26
27
like this:
27
28
28
29
```javascript
29
30
alert(require('myModule').foo());
30
31
```
31
32
32
-
Check the article on [JavaScript Modules](js-modules.md) for more information on the topic of JavaScript module systems.
33
+
For more information about JavaScript module systems, see [JavaScript Modules](js-modules.md).
33
34
34
35
## Package structure
35
36
36
-
Kotlin exposes its package structure to JavaScript, so unless you define your declarations in the root package,
37
-
you have to use fully qualified names in JavaScript. For example:
37
+
For most of the module systems (CommonJS, Plain, and UMD), Kotlin exposes its package structure to JavaScript.
38
+
Unless you define your declarations in the root package, you have to use fully qualified names in JavaScript.
39
+
For example:
38
40
39
41
```kotlin
40
42
packagemy.qualified.packagename
41
43
42
44
funfoo() ="Hello"
43
45
```
44
46
45
-
When using UMD or CommonJS, for example, your callsite could look like this:
47
+
For example, when using UMD or CommonJS, your call site could look like this:
0 commit comments