diff options
author | Li Jin <dragon-fly@qq.com> | 2025-08-26 15:11:17 +0800 |
---|---|---|
committer | Li Jin <dragon-fly@qq.com> | 2025-08-26 15:11:17 +0800 |
commit | df30bf7958953740f5c6f59ff3a0495f8b15f582 (patch) | |
tree | 4c0acab3e579cc4cbd2660158f8e2354fe0ef230 /doc/docs/zh | |
parent | d90857cc05cd0820a2057c547e95b02d24d15412 (diff) | |
download | yuescript-df30bf7958953740f5c6f59ff3a0495f8b15f582.tar.gz yuescript-df30bf7958953740f5c6f59ff3a0495f8b15f582.tar.bz2 yuescript-df30bf7958953740f5c6f59ff3a0495f8b15f582.zip |
Updated docs. [skip CI]
Diffstat (limited to 'doc/docs/zh')
-rwxr-xr-x | doc/docs/zh/doc/README.md | 35 |
1 files changed, 35 insertions, 0 deletions
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 | 反向回调用于减少函数回调的嵌套。它们使用指向左侧的箭头,并且默认会被定义为传入后续函数调用的最后一个参数。它的语法大部分与常规箭头函数相同,只是它指向另一方向,并且后续的函数体不需要进行缩进。 |