I have this code
function changeFunc() {
return function(target: any, title: string, descriptor: PropertyDescriptor) {
descriptor.value = function () {
console.log(this.name);
};
return descriptor;
}
}
class Man {
name: string = "asdsds";
constructor(name: string) {
this.name = name;
}
@changeFunc()
getName() {
console.log("Hello");
}
}
var man = new Man('Manos Serifios');
man.getName();
In other words i try (with the decorator) to change the method
getName() {
console.log("Hello");
}
with this
function () {
console.log(this.name);
}
but this.name evaluated as undefined.
If i console log the "this" it seems that is the right(instance man).
descriptor.value = function () { console.log(target.name); };. I am just guessing and have no experience with typescript decorators