diff options
Diffstat (limited to 'doc/docs/zh/doc/language-basics/attributes.md')
| -rw-r--r-- | doc/docs/zh/doc/language-basics/attributes.md | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/doc/docs/zh/doc/language-basics/attributes.md b/doc/docs/zh/doc/language-basics/attributes.md new file mode 100644 index 0000000..3dc3b0b --- /dev/null +++ b/doc/docs/zh/doc/language-basics/attributes.md | |||
| @@ -0,0 +1,46 @@ | |||
| 1 | # 属性 | ||
| 2 | |||
| 3 |   月之脚本现在提供了 Lua 5.4 新增的叫做属性的语法支持。在月之脚本编译到的 Lua 目标版本低于 5.4 时,你仍然可以同时使用`const` 和 `close` 的属性声明语法,并获得常量检查和作用域回调的功能。 | ||
| 4 | |||
| 5 | ```yuescript | ||
| 6 | const a = 123 | ||
| 7 | close _ = <close>: -> print "超出范围。" | ||
| 8 | ``` | ||
| 9 | <YueDisplay> | ||
| 10 | |||
| 11 | ```yue | ||
| 12 | const a = 123 | ||
| 13 | close _ = <close>: -> print "超出范围。" | ||
| 14 | ``` | ||
| 15 | |||
| 16 | </YueDisplay> | ||
| 17 | |||
| 18 |   你可以对进行解构得到的变量标记为常量。 | ||
| 19 | |||
| 20 | ```yuescript | ||
| 21 | const {:a, :b, c, d} = tb | ||
| 22 | -- a = 1 | ||
| 23 | ``` | ||
| 24 | <YueDisplay> | ||
| 25 | |||
| 26 | ```yue | ||
| 27 | const {:a, :b, c, d} = tb | ||
| 28 | -- a = 1 | ||
| 29 | ``` | ||
| 30 | |||
| 31 | </YueDisplay> | ||
| 32 | |||
| 33 |   你也可以声明全局变量为常量。 | ||
| 34 | |||
| 35 | ```yuescript | ||
| 36 | global const Constant = 123 | ||
| 37 | -- Constant = 1 | ||
| 38 | ``` | ||
| 39 | <YueDisplay> | ||
| 40 | |||
| 41 | ```yue | ||
| 42 | global const Constant = 123 | ||
| 43 | -- Constant = 1 | ||
| 44 | ``` | ||
| 45 | |||
| 46 | </YueDisplay> | ||
