From df30bf7958953740f5c6f59ff3a0495f8b15f582 Mon Sep 17 00:00:00 2001 From: Li Jin Date: Tue, 26 Aug 2025 15:11:17 +0800 Subject: Updated docs. [skip CI] --- doc/docs/doc/README.md | 36 ++++++++++++++++++++++++++++++++++++ doc/docs/zh/doc/README.md | 35 +++++++++++++++++++++++++++++++++++ 2 files changed, 71 insertions(+) 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, +### Parameter Destructuring + +YueScript now supports destructuring function parameters when the argument is an object. Two forms of destructuring table literals are available: + +* **Curly-brace wrapped literals/object parameters**, allowing optional default values when fields are missing (e.g., `{:a, :b}`, `{a: a1 = 123}`). + +* **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. + +```moonscript +f1 = (:a, :b, :c) -> + print a, b, c + +f1 a: 1, b: "2", c: {} + +f2 = ({a: a1 = 123, :b = 'abc'}, c = {}) -> + print a, b, c + +arg1 = {a: 0} +f2 arg1, arg2 +``` + +
+f1 = (:a, :b, :c) ->
+  print a, b, c
+
+f1 a: 1, b: "2", c: {}
+
+f2 = ({a: a1 = 123, :b = 'abc'}, c = {}) ->
+print a, b, c
+
+arg1 = {a: 0}
+f2 arg1, arg2
+
+
+ + ## Backcalls 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, +### 参数解构 + +月之脚本支持在函数形参位置对传入对象进行解构。适用两类解构表子面量: + +- 使用 {} 包裹的字面量/对象形参,支持提供获得空字段时的默认值(例如 {:a, :b}、{a: a1 = 123})。 + +- 无 {} 包裹、以键值/简写键序列开头,直至遇到其它表达式终止(例如 :a, b: b1, :c),表示从同一个对象中解构多个字段。 + +```moonscript +f1 = (:a, :b, :c) -> + print a, b, c + +f1 a: 1, b: "2", c: {} + +f2 = ({a: a1 = 123, :b = 'abc'}, c = {}) -> + print a, b, c + +arg1 = {a: 0} +f2 arg1, arg2 +``` + +
+f1 = (:a, :b, :c) ->
+  print a, b, c
+
+f1 a: 1, b: "2", c: {}
+
+f2 = ({a: a1 = 123, :b = 'abc'}, c = {}) ->
+  print a, b, c
+
+arg1 = {a: 0}
+f2 arg1, arg2
+
+
+ ## 反向回调 反向回调用于减少函数回调的嵌套。它们使用指向左侧的箭头,并且默认会被定义为传入后续函数调用的最后一个参数。它的语法大部分与常规箭头函数相同,只是它指向另一方向,并且后续的函数体不需要进行缩进。 -- cgit v1.2.3-55-g6feb