From a9d28cb615d2bdc09d2482d5262951f2afc8d6e1 Mon Sep 17 00:00:00 2001 From: Li Jin Date: Mon, 26 May 2025 15:52:07 +0800 Subject: Added doc for `with?` syntax. --- doc/docs/doc/README.md | 14 +++++++++++++- doc/docs/zh/doc/README.md | 15 ++++++++++++++- 2 files changed, 27 insertions(+), 2 deletions(-) (limited to 'doc') diff --git a/doc/docs/doc/README.md b/doc/docs/doc/README.md index 7e9b454..a970baa 100755 --- a/doc/docs/doc/README.md +++ b/doc/docs/doc/README.md @@ -3538,7 +3538,7 @@ with str := "Hello" -Accessing special keys with `[]` in a `with` statement. +You can access special keys with `[]` in a `with` statement. ```moonscript with tb @@ -3561,6 +3561,18 @@ with tb +`with?` is an enhanced version of `with` syntax, which introduces an existential check to safely access objects that may be nil without explicit null checks. + +```moonscript +with? obj + print obj.name +``` + +
+with? obj
+  print obj.name
+
+
## Do diff --git a/doc/docs/zh/doc/README.md b/doc/docs/zh/doc/README.md index da90fa6..2d4af18 100755 --- a/doc/docs/zh/doc/README.md +++ b/doc/docs/zh/doc/README.md @@ -3494,7 +3494,7 @@ with str := "你好" -在with语句中可以使用`[]`访问特殊键。 +你可以在 `with` 语句中使用 `[]` 访问特殊键。 ```moonscript with tb @@ -3517,6 +3517,19 @@ with tb +`with?` 是 `with` 语法的一个增强版本,引入了存在性检查,用于在不显式判空的情况下安全访问可能为 nil 的对象。 + +```moonscript +with? obj + print obj.name +``` + +
+with? obj
+  print obj.name
+
+
+ ## do 语句 当用作语句时,do语句的作用就像在Lua中差不多。 -- cgit v1.2.3-55-g6feb