> For the complete documentation index, see [llms.txt](https://narro.gitbook.io/tinyts-handbook-cn/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://narro.gitbook.io/tinyts-handbook-cn/introduction/decorator.md).

# 装饰器

装饰器（[decorator](https://zhongsp.gitbooks.io/typescript-handbook/content/doc/handbook/Decorators.html)）是typescript中的一个高级特性，用于定义类、方法等的元数据。在tinyts的核心库中，我们实现了view和partialView两个装饰器。分别用于定义视图模型类的控件属性和子视图属性。\
view —— 用于定义视图模型类的控件属性。在一个视图模型中，在某个属性上定义@view(Class)指示该属性是Class类型的控件，其中Class必须是继承自View的类的类名。示例如下：

```typescript
 import {Button} from 'tinyts/controls/Button';

 class A{
   @view(Button)
   btnSubmit:Button;
 }
```

示例中，A类有一个成员属性btnSubmit，该属性被定义为Button类型，并被指示为Button类型（一般情况下，被定义的类型与被指示的类型是保持一致的）。\
partialView —— 用于定义视图模型的子视图属性。partialView的用法与view相似，不过使用partialView指示的类型必须继承自ViewGroup或VirtualView类。关于子视图的用法，我们将在后续的章节中介绍。\
当一个视图模型类的属性被指示为控件或子视图时，视图模型类将会在初始化过程中注入这些属性。注入过程将在下一节详细介绍。
