> For the complete documentation index, see [llms.txt](https://note.niefee.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://note.niefee.com/directory-2/decorator.md).

# Decorator

暂停更新 由于这个特性支持有限，以后再更新。

## 2017年04月23日

修饰器（Decorator）是一个函数，用来修改类的行为。

修饰器对类的行为的改变，是代码编译时发生的，而不是在运行时。

```javascript
function testable(target) {
  target.isTestable = true;
}

@testable
class MyTestableClass {}

console.log(MyTestableClass.isTestable) // true
```

`@testable`就是一个修饰器。它修改了`MyTestableClass`这个类的行为，为它加上了静态属性`isTestable`。
