diff options
Diffstat (limited to 'doc/docs')
| -rwxr-xr-x | doc/docs/doc/README.md | 36 | ||||
| -rwxr-xr-x | doc/docs/zh/doc/README.md | 35 |
2 files changed, 71 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. |
diff --git a/doc/docs/zh/doc/README.md b/doc/docs/zh/doc/README.md index 15f4768..09ba9ee 100755 --- a/doc/docs/zh/doc/README.md +++ b/doc/docs/zh/doc/README.md | |||
| @@ -2086,6 +2086,41 @@ if func 1, 2, 3, | |||
| 2086 | </pre> | 2086 | </pre> |
| 2087 | </YueDisplay> | 2087 | </YueDisplay> |
| 2088 | 2088 | ||
| 2089 | ### 参数解构 | ||
| 2090 | |||
| 2091 | 月之脚本支持在函数形参位置对传入对象进行解构。适用两类解构表子面量: | ||
| 2092 | |||
| 2093 | - 使用 {} 包裹的字面量/对象形参,支持提供获得空字段时的默认值(例如 {:a, :b}、{a: a1 = 123})。 | ||
| 2094 | |||
| 2095 | - 无 {} 包裹、以键值/简写键序列开头,直至遇到其它表达式终止(例如 :a, b: b1, :c),表示从同一个对象中解构多个字段。 | ||
| 2096 | |||
| 2097 | ```moonscript | ||
| 2098 | f1 = (:a, :b, :c) -> | ||
| 2099 | print a, b, c | ||
| 2100 | |||
| 2101 | f1 a: 1, b: "2", c: {} | ||
| 2102 | |||
| 2103 | f2 = ({a: a1 = 123, :b = 'abc'}, c = {}) -> | ||
| 2104 | print a, b, c | ||
| 2105 | |||
| 2106 | arg1 = {a: 0} | ||
| 2107 | f2 arg1, arg2 | ||
| 2108 | ``` | ||
| 2109 | <YueDisplay> | ||
| 2110 | <pre> | ||
| 2111 | f1 = (:a, :b, :c) -> | ||
| 2112 | print a, b, c | ||
| 2113 | |||
| 2114 | f1 a: 1, b: "2", c: {} | ||
| 2115 | |||
| 2116 | f2 = ({a: a1 = 123, :b = 'abc'}, c = {}) -> | ||
| 2117 | print a, b, c | ||
| 2118 | |||
| 2119 | arg1 = {a: 0} | ||
| 2120 | f2 arg1, arg2 | ||
| 2121 | </pre> | ||
| 2122 | </YueDisplay> | ||
| 2123 | |||
| 2089 | ## 反向回调 | 2124 | ## 反向回调 |
| 2090 | 2125 | ||
| 2091 | 反向回调用于减少函数回调的嵌套。它们使用指向左侧的箭头,并且默认会被定义为传入后续函数调用的最后一个参数。它的语法大部分与常规箭头函数相同,只是它指向另一方向,并且后续的函数体不需要进行缩进。 | 2126 | 反向回调用于减少函数回调的嵌套。它们使用指向左侧的箭头,并且默认会被定义为传入后续函数调用的最后一个参数。它的语法大部分与常规箭头函数相同,只是它指向另一方向,并且后续的函数体不需要进行缩进。 |
