File tree Expand file tree Collapse file tree 4 files changed +34
-22
lines changed Expand file tree Collapse file tree 4 files changed +34
-22
lines changed Original file line number Diff line number Diff 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!
Original file line number Diff line number Diff line change 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.
Original file line number Diff line number Diff 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
2323Please [ refer to the docs] ( https://kotlinlang.org/docs/reference/js-interop.html#external-modifier ) in order
2424to learn more about describing existing JavaScript API.
Original file line number Diff line number Diff line change 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 )
You can’t perform that action at this time.
0 commit comments