aboutsummaryrefslogtreecommitdiff
path: root/doc/docs
diff options
context:
space:
mode:
Diffstat (limited to 'doc/docs')
-rwxr-xr-xdoc/docs/doc/README.md36
-rwxr-xr-xdoc/docs/zh/doc/README.md35
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
2131YueScript 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
2138f1 = (:a, :b, :c) ->
2139 print a, b, c
2140
2141f1 a: 1, b: "2", c: {}
2142
2143f2 = ({a: a1 = 123, :b = 'abc'}, c = {}) ->
2144 print a, b, c
2145
2146arg1 = {a: 0}
2147f2 arg1, arg2
2148```
2149<YueDisplay>
2150<pre>
2151f1 = (:a, :b, :c) ->
2152 print a, b, c
2153
2154f1 a: 1, b: "2", c: {}
2155
2156f2 = ({a: a1 = 123, :b = 'abc'}, c = {}) ->
2157print a, b, c
2158
2159arg1 = {a: 0}
2160f2 arg1, arg2
2161</pre>
2162</YueDisplay>
2163
2164
2129## Backcalls 2165## Backcalls
2130 2166
2131Backcalls 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. 2167Backcalls 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
2098f1 = (:a, :b, :c) ->
2099 print a, b, c
2100
2101f1 a: 1, b: "2", c: {}
2102
2103f2 = ({a: a1 = 123, :b = 'abc'}, c = {}) ->
2104 print a, b, c
2105
2106arg1 = {a: 0}
2107f2 arg1, arg2
2108```
2109<YueDisplay>
2110<pre>
2111f1 = (:a, :b, :c) ->
2112 print a, b, c
2113
2114f1 a: 1, b: "2", c: {}
2115
2116f2 = ({a: a1 = 123, :b = 'abc'}, c = {}) ->
2117 print a, b, c
2118
2119arg1 = {a: 0}
2120f2 arg1, arg2
2121</pre>
2122</YueDisplay>
2123
2089## 反向回调 2124## 反向回调
2090 2125
2091反向回调用于减少函数回调的嵌套。它们使用指向左侧的箭头,并且默认会被定义为传入后续函数调用的最后一个参数。它的语法大部分与常规箭头函数相同,只是它指向另一方向,并且后续的函数体不需要进行缩进。 2126反向回调用于减少函数回调的嵌套。它们使用指向左侧的箭头,并且默认会被定义为传入后续函数调用的最后一个参数。它的语法大部分与常规箭头函数相同,只是它指向另一方向,并且后续的函数体不需要进行缩进。