diff options
| author | Li Jin <dragon-fly@qq.com> | 2023-08-21 16:52:31 +0800 |
|---|---|---|
| committer | Li Jin <dragon-fly@qq.com> | 2023-08-21 16:52:31 +0800 |
| commit | eb48c686a7ab5bd3f3f3a8628ed0423872a932c6 (patch) | |
| tree | d4e66ae42b1c41b7a06b9f32eefdb7f138aae135 | |
| parent | b0c461305cfc0dd1cf8235197224130a9bd78d68 (diff) | |
| download | yuescript-eb48c686a7ab5bd3f3f3a8628ed0423872a932c6.tar.gz yuescript-eb48c686a7ab5bd3f3f3a8628ed0423872a932c6.tar.bz2 yuescript-eb48c686a7ab5bd3f3f3a8628ed0423872a932c6.zip | |
fix issue #146.
Diffstat (limited to '')
| -rwxr-xr-x | doc/docs/doc/README.md | 52 |
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 = | |||
| 43 | p apple.color, apple.<index> if apple.<>? | 43 | p apple.color, apple.<index> if apple.<>? |
| 44 | 44 | ||
| 45 | -- js-like export syntax | 45 | -- js-like export syntax |
| 46 | export yuescript = "ζδΉθζ¬" | 46 | export π = "ζδΉθζ¬" |
| 47 | ``` | 47 | ``` |
| 48 | <YueDisplay> | 48 | <YueDisplay> |
| 49 | <pre> | 49 | <pre> |
| @@ -75,7 +75,7 @@ apple = | |||
| 75 | p apple.color, apple.<index> if apple.<>? | 75 | p apple.color, apple.<index> if apple.<>? |
| 76 | 76 | ||
| 77 | -- js-like export syntax | 77 | -- js-like export syntax |
| 78 | export yuescript = "ζδΉθζ¬" | 78 | export π = "ζδΉθζ¬" |
| 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 | |||
| 3032 | To reduce the boilerplate code for definition of simple value objects. You can write a simple class like: | ||
| 3033 | |||
| 3034 | ```moonscript | ||
| 3035 | class Something | ||
| 3036 | new: (@foo, @bar, @@biz, @@baz) => | ||
| 3037 | |||
| 3038 | -- Which is short for | ||
| 3039 | |||
| 3040 | class Something | ||
| 3041 | new: (foo, bar, biz, baz) => | ||
| 3042 | @foo = foo | ||
| 3043 | @bar = bar | ||
| 3044 | @@biz = biz | ||
| 3045 | @@baz = baz | ||
| 3046 | ``` | ||
| 3047 | <YueDisplay> | ||
| 3048 | <pre> | ||
| 3049 | class Something | ||
| 3050 | new: (@foo, @bar, @@biz, @@baz) => | ||
| 3051 | |||
| 3052 | -- Which is short for | ||
| 3053 | |||
| 3054 | class Something | ||
| 3055 | new: (foo, bar, biz, baz) => | ||
| 3056 | @foo = foo | ||
| 3057 | @bar = bar | ||
| 3058 | @@biz = biz | ||
| 3059 | @@baz = baz | ||
| 3060 | </pre> | ||
| 3061 | </YueDisplay> | ||
| 3062 | |||
| 3063 | You can also use this syntax for a common function to initialize a object's fields. | ||
| 3064 | |||
| 3065 | ```moonscript | ||
| 3066 | new = (@fieldA, @fieldB)=> @ | ||
| 3067 | obj = new {}, 123, "abc" | ||
| 3068 | print obj | ||
| 3069 | ``` | ||
| 3070 | <YueDisplay> | ||
| 3071 | <pre> | ||
| 3072 | new = (@fieldA, @fieldB)=> @ | ||
| 3073 | obj = new {}, 123, "abc" | ||
| 3074 | print obj | ||
| 3075 | </pre> | ||
| 3076 | </YueDisplay> | ||
| 3077 | |||
| 3030 | ### Class Expressions | 3078 | ### Class Expressions |
| 3031 | 3079 | ||
| 3032 | The class syntax can also be used as an expression which can be assigned to a variable or explicitly returned. | 3080 | The class syntax can also be used as an expression which can be assigned to a variable or explicitly returned. |
