diff options
Diffstat (limited to 'doc/docs/doc/README.md')
| -rwxr-xr-x | doc/docs/doc/README.md | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/doc/docs/doc/README.md b/doc/docs/doc/README.md index f0d67a5..309e124 100755 --- a/doc/docs/doc/README.md +++ b/doc/docs/doc/README.md | |||
| @@ -2126,6 +2126,42 @@ if func 1, 2, 3, | |||
| 2126 | </pre> | 2126 | </pre> |
| 2127 | </YueDisplay> | 2127 | </YueDisplay> |
| 2128 | 2128 | ||
| 2129 | ### Parameter Destructuring | ||
| 2130 | |||
| 2131 | YueScript now supports destructuring function parameters when the argument is an object. Two forms of destructuring table literals are available: | ||
| 2132 | |||
| 2133 | * **Curly-brace wrapped literals/object parameters**, allowing optional default values when fields are missing (e.g., `{:a, :b}`, `{a: a1 = 123}`). | ||
| 2134 | |||
| 2135 | * **Unwrapped simple table syntax**, starting with a sequence of key-value or shorthand bindings and continuing until another expression terminates it (e.g., `:a, b: b1, :c`). This form extracts multiple fields from the same object. | ||
| 2136 | |||
| 2137 | ```moonscript | ||
| 2138 | f1 = (:a, :b, :c) -> | ||
| 2139 | print a, b, c | ||
| 2140 | |||
| 2141 | f1 a: 1, b: "2", c: {} | ||
| 2142 | |||
| 2143 | f2 = ({a: a1 = 123, :b = 'abc'}, c = {}) -> | ||
| 2144 | print a, b, c | ||
| 2145 | |||
| 2146 | arg1 = {a: 0} | ||
| 2147 | f2 arg1, arg2 | ||
| 2148 | ``` | ||
| 2149 | <YueDisplay> | ||
| 2150 | <pre> | ||
| 2151 | f1 = (:a, :b, :c) -> | ||
| 2152 | print a, b, c | ||
| 2153 | |||
| 2154 | f1 a: 1, b: "2", c: {} | ||
| 2155 | |||
| 2156 | f2 = ({a: a1 = 123, :b = 'abc'}, c = {}) -> | ||
| 2157 | print a, b, c | ||
| 2158 | |||
| 2159 | arg1 = {a: 0} | ||
| 2160 | f2 arg1, arg2 | ||
| 2161 | </pre> | ||
| 2162 | </YueDisplay> | ||
| 2163 | |||
| 2164 | |||
| 2129 | ## Backcalls | 2165 | ## Backcalls |
| 2130 | 2166 | ||
| 2131 | Backcalls are used for unnesting callbacks. They are defined using arrows pointed to the left as the last parameter by default filling in a function call. All the syntax is mostly the same as regular arrow functions except that it is just pointing the other way and the function body does not require indent. | 2167 | Backcalls are used for unnesting callbacks. They are defined using arrows pointed to the left as the last parameter by default filling in a function call. All the syntax is mostly the same as regular arrow functions except that it is just pointing the other way and the function body does not require indent. |
