自定义标签装饰器

原文链接

创建你自己的装饰器很简单:

let throwable = tagged("canThrow", true);
let notThrowable = tagged("canThrow", false);

@injectable()
class Ninja implements Ninja {
    public katana: Weapon;
    public shuriken: Weapon;
    public constructor(
        @inject("Weapon") @notThrowable katana: Weapon,
        @inject("Weapon") @throwable shuriken: Weapon
    ) {
        this.katana = katana;
        this.shuriken = shuriken;
    }
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
上次更新: 1/5/2020, 1:11:10 PM