Skip to content

Commit 8941450

Browse files
Merge pull request Kotlin#51 from p7nov/js-revised
docs: revised Kotlin/JS
2 parents 79982fd + 9d6f83c commit 8941450

File tree

4 files changed

+34
-22
lines changed

4 files changed

+34
-22
lines changed

examples/09_Kotlin_JS/01_dynamic.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,9 @@ fun main(){
3030

3131
</div>
3232

33-
1. Any value can be assigned to variable to `dynamic` type
34-
2. Dynamic value can be assigned to anything.
35-
3. Dynamic value can be passed as argument to any function
36-
4. Any property or function with any arguments can be called on `dynamic` value
37-
5. Dynamic call always returns dynamic value, so it is possible to chain them.
38-
6. Operators, assignments and indexed access (`[..]`) are translated "as is". Beware!
33+
1. Any value can be assigned to a `dynamic` variable type.
34+
2. A dynamic value can be assigned to anything.
35+
3. A dynamic variable can be passed as an argument to any function.
36+
4. Any property or function with any arguments can be called on a `dynamic` variable.
37+
5. A function call on a `dynamic` variable always returns a dynamic value, so it is possible to chain the calls.
38+
6. Operators, assignments, and indexed access (`[..]`) are translated "as is". Beware!

examples/09_Kotlin_JS/02_js_function.md

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,21 @@
11
# JS function
22

3-
You can inline some JavaScript code into your Kotlin code using the `js("…")` function.
4-
Should be used with extreme care.
3+
You can inline JavaScript code into your Kotlin code using the js("…") function.
4+
This should be used with extreme care.
5+
6+
7+
<div class="language-kotlin" theme="idea" data-min-compiler-version="1.3" data-target-platform="js">
8+
9+
```kotlin
10+
fun main() {
11+
// sampleStart
12+
js("alert(\"alert from Kotlin!\")") // 1
13+
// sampleEnd
14+
}
15+
```
16+
</div>
17+
18+
1. Sending a JavaScript alert from a Kotlin function.
519

620
<div class="language-kotlin" theme="idea" data-min-compiler-version="1.3" data-target-platform="js">
721

@@ -19,6 +33,6 @@ fun main(){
1933

2034
</div>
2135

22-
1. Create a JavaScript object literal. The `js(...)` function return type is `dynamic`.
23-
2. Add some properties by utilizing the `dynamic` type capabilities.
24-
3. Pass the JSON to JavaScript API.
36+
1. Creates a JavaScript object literal. The `js(...)` function return type is `dynamic`.
37+
2. Adds some properties by utilizing the `dynamic` type capabilities.
38+
3. Passes the JSON to JavaScript API.

examples/09_Kotlin_JS/03_external.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,11 @@ fun main() {
1414

1515
</div>
1616

17-
1. Declare an existing JavaScript function `alert` which takes a single `String` argument
18-
2. Use it as if it was regular Kotlin.
17+
1. Declares an existing JavaScript function `alert` which takes a single `String` argument.
18+
2. Uses `alert` as if it were regular Kotlin.
1919

20-
Note that Kotlin checks during compilation that exactly a single argument of type `String` is passed.
21-
That prevents a number of bugs even when using pure JavaScript API - same as with regular Kotlin.
20+
Note that Kotlin checks during compilation, that a single argument of type String is passed.
21+
Such a check prevents some bugs even when using pure JavaScript API.
2222

2323
Please [refer to the docs](https://kotlinlang.org/docs/reference/js-interop.html#external-modifier) in order
2424
to learn more about describing existing JavaScript API.

examples/09_Kotlin_JS/06_HtmlBuilder.md

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
11
# Html Builder
22

3-
This is an example of a Type-Safe Groovy-style Builder
4-
5-
Builders are good for declaratively describing data in your code.
6-
In this example we show how to describe an HTML page in Kotlin
3+
Kotlin provides you with an option to describe structured data in a declarative style with _builders_.
74

5+
Below is an example of a type-safe Groovy-style builder. In this example, we will describe an HTML page in Kotlin.
86

97
<div class="language-kotlin" theme="idea" data-min-compiler-version="1.3" data-target-platform="canvas" data-output-height="400">
108

@@ -127,8 +125,8 @@ fun html(init: HTML.() -> Unit): HTML {
127125
This means that we need to pass an instance of type `HTML` (a receiver) to the function,
128126
and we can call members of that instance inside the function.
129127

130-
2. `head` and `body` are member functions of `HTML`.
128+
2. `head` and `body` are member functions of the`HTML` class.
131129

132-
3. Text us added to tags by calling `unaryPlus()` operation.
130+
3. Adds the text to tags by calling the `unaryPlus()` operation, like `+"HTML encoding with Kotlin"`.
133131

134-
For details see: [Type Safe Builders](http://kotlinlang.org/docs/reference/type-safe-builders.html)
132+
For details see: [Type Safe Builders](http://kotlinlang.org/docs/reference/type-safe-builders.html)

0 commit comments

Comments
 (0)