aboutsummaryrefslogtreecommitdiff
path: root/doc
diff options
context:
space:
mode:
authorLi Jin <dragon-fly@qq.com>2023-08-21 16:52:31 +0800
committerLi Jin <dragon-fly@qq.com>2023-08-21 16:52:31 +0800
commiteb48c686a7ab5bd3f3f3a8628ed0423872a932c6 (patch)
treed4e66ae42b1c41b7a06b9f32eefdb7f138aae135 /doc
parentb0c461305cfc0dd1cf8235197224130a9bd78d68 (diff)
downloadyuescript-eb48c686a7ab5bd3f3f3a8628ed0423872a932c6.tar.gz
yuescript-eb48c686a7ab5bd3f3f3a8628ed0423872a932c6.tar.bz2
yuescript-eb48c686a7ab5bd3f3f3a8628ed0423872a932c6.zip
fix issue #146.
Diffstat (limited to 'doc')
-rwxr-xr-xdoc/docs/doc/README.md52
1 files changed, 50 insertions, 2 deletions
diff --git a/doc/docs/doc/README.md b/doc/docs/doc/README.md
index 7e4aa22..fbf7e50 100755
--- a/doc/docs/doc/README.md
+++ b/doc/docs/doc/README.md
@@ -43,7 +43,7 @@ apple =
43p apple.color, apple.<index> if apple.<>? 43p apple.color, apple.<index> if apple.<>?
44 44
45-- js-like export syntax 45-- js-like export syntax
46export yuescript = "ζœˆδΉ‹θ„šζœ¬" 46export πŸŒ› = "ζœˆδΉ‹θ„šζœ¬"
47``` 47```
48<YueDisplay> 48<YueDisplay>
49<pre> 49<pre>
@@ -75,7 +75,7 @@ apple =
75p apple.color, apple.&lt;index&gt; if apple.&lt;&gt;? 75p apple.color, apple.&lt;index&gt; if apple.&lt;&gt;?
76 76
77-- js-like export syntax 77-- js-like export syntax
78export yuescript = "ζœˆδΉ‹θ„šζœ¬" 78export πŸŒ› = "ζœˆδΉ‹θ„šζœ¬"
79</pre> 79</pre>
80</YueDisplay> 80</YueDisplay>
81 81
@@ -3027,6 +3027,54 @@ some_instance_method = (...)=> @@ ...
3027</pre> 3027</pre>
3028</YueDisplay> 3028</YueDisplay>
3029 3029
3030### Constructor Property Promotion
3031
3032To reduce the boilerplate code for definition of simple value objects. You can write a simple class like:
3033
3034```moonscript
3035class Something
3036 new: (@foo, @bar, @@biz, @@baz) =>
3037
3038-- Which is short for
3039
3040class Something
3041 new: (foo, bar, biz, baz) =>
3042 @foo = foo
3043 @bar = bar
3044 @@biz = biz
3045 @@baz = baz
3046```
3047<YueDisplay>
3048<pre>
3049class Something
3050 new: (@foo, @bar, @@biz, @@baz) =>
3051
3052-- Which is short for
3053
3054class Something
3055 new: (foo, bar, biz, baz) =>
3056 @foo = foo
3057 @bar = bar
3058 @@biz = biz
3059 @@baz = baz
3060</pre>
3061</YueDisplay>
3062
3063You can also use this syntax for a common function to initialize a object's fields.
3064
3065```moonscript
3066new = (@fieldA, @fieldB)=> @
3067obj = new {}, 123, "abc"
3068print obj
3069```
3070<YueDisplay>
3071<pre>
3072new = (@fieldA, @fieldB)=> @
3073obj = new {}, 123, "abc"
3074print obj
3075</pre>
3076</YueDisplay>
3077
3030### Class Expressions 3078### Class Expressions
3031 3079
3032The class syntax can also be used as an expression which can be assigned to a variable or explicitly returned. 3080The class syntax can also be used as an expression which can be assigned to a variable or explicitly returned.