# TypeScript: 类的装饰器(二)
# 类的装饰器执行时机
接上文,我们引出了 TypeScript 类的装饰器后,接下来,去挖掘下它的特性
PS:上文,TypeScript: 类的装饰器(一)
先写一小段类的装饰器的代码:
function addDecorator(constructor: any) {
console.log("add decorator");
}
@addDecorator
class Test {}
const t: Test = new Test();
此时运行:npm run dev

function addDecorator(constructor: any) {
console.log("add decorator");
}
@addDecorator
class Test {}
const t: Test = new Test();
const t1: Test = new Test();
此时运行:npm run dev

function addDecorator(constructor: any) {
console.log("add decorator");
}
@addDecorator
class Test {}
此时运行:npm run dev

# 类的装饰器执行顺序
我们再加一个装饰器,代码变为如下:
function addDecorator(constructor: any) {
console.log("add decorator");
}
function addNextDecorator(constructor: any) {
console.log("add next decorator");
}
@addDecorator
@addNextDecorator
class Test {}
此时运行:npm run dev
