属性装饰器在运行的时候会作为一个函数被调用,传入下面两个参数
1.对于实例成员是,第一个参数类的原型对象。
2.第二个参数,是类的属性名
class Student{
@decorateProperty("top250")
public url:string|undefined;
getData(){
console.log(this.url)
}
}
function decorateProperty(parmas:any){
return function(target:any,attr:any){
console.log(target); //类的原型对象
console.log(attr); //属性名
target[attr] = parmas;
}
}
var s:any = new Student();
console.log(s.url);