Open phymo opened 2 years ago
// 装饰器函数 sealed, 接受类的constructor函数
function sealed(constructor: Function) {
console.log('sealed');
// Object.seal 封闭一个对象 不可配置
Object.seal(constructor);
Object.seal(constructor.prototype);
}
@sealed
class Greeter {
greeting: string;
constructor(message: string) {
this.greeting = message;
greatting() {
return 'hello' + this.greeting;
}
}
function enumerable(value: boolean) {
// 注意返回的装饰器函数的三个参数
return function (target: any, propertyKey: string, descriptor: PropertyDescriptor) {
descriptor.enumerable = value;
};
}
class Greeter {
greeting: string;
constructor(message: string) {
this.greeting = message;
}
@enumerable(false)
greet() {
return "Hello, " + this.greeting;
}
}