diff options
Diffstat (limited to 'doc/docs/zh/doc/objects/object-oriented-programming.md')
| -rw-r--r-- | doc/docs/zh/doc/objects/object-oriented-programming.md | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/doc/docs/zh/doc/objects/object-oriented-programming.md b/doc/docs/zh/doc/objects/object-oriented-programming.md index 04f816a..270c2b3 100644 --- a/doc/docs/zh/doc/objects/object-oriented-programming.md +++ b/doc/docs/zh/doc/objects/object-oriented-programming.md | |||
| @@ -38,6 +38,28 @@ class Inventory | |||
| 38 | 38 | ||
| 39 |   此外,“@” 前缀在变量名上起到了简化作用,代表 “self”。例如,`@items` 就等同于 `self.items`。 | 39 |   此外,“@” 前缀在变量名上起到了简化作用,代表 “self”。例如,`@items` 就等同于 `self.items`。 |
| 40 | 40 | ||
| 41 |   类定义块中也支持通过尖括号写元方法字段,例如 `<tostring>`。 | ||
| 42 | |||
| 43 | ```yuescript | ||
| 44 | class User | ||
| 45 | new: (@name) => | ||
| 46 | <tostring>: => "User(#{@name})" | ||
| 47 | |||
| 48 | print tostring User "Yue" | ||
| 49 | ``` | ||
| 50 | |||
| 51 | <YueDisplay> | ||
| 52 | |||
| 53 | ```yue | ||
| 54 | class User | ||
| 55 | new: (@name) => | ||
| 56 | <tostring>: => "User(#{@name})" | ||
| 57 | |||
| 58 | print tostring User "Yue" | ||
| 59 | ``` | ||
| 60 | |||
| 61 | </YueDisplay> | ||
| 62 | |||
| 41 |   为了创建类的一个新实例,可以将类名当作一个函数来调用,这样就可以生成并返回一个新的实例。 | 63 |   为了创建类的一个新实例,可以将类名当作一个函数来调用,这样就可以生成并返回一个新的实例。 |
| 42 | 64 | ||
| 43 | ```yuescript | 65 | ```yuescript |
