Check out this showcase:
function Decorator(SampleClass: Sample) {
console.log('Inside the decorator function');
return function (args) {
console.log('Inside the high order function of the decorator: ', args);
let sample = new SampleClass();
}
}
@Decorator
class Sample {
a = 1;
static b = 2;
constructor(args) {
console.log('Inside the constructor of Sample')
console.log('Instance values of Sample: ', this.a);
console.log('Static value of Sample: ', Sample.b);
}
}
new Sample(123);
After compiling and running the code, it displays:
Inside the decorator function
Inside the high order function of the decorator: 123
Inside the constructor of Sample
Instance values of Sample: 1
Static value of Sample: undefined
I have noticed that I can access the static value b
in the high order function using SampleClass.b
. However, accessing it within an instance of Sample
seems to be challenging.