I'm struggling to grasp this code:
function Logger(target) {
console.log('The decorated class:', target);
}
@Logger
class SampleClass {
constructor() {
console.log('Hey!');
}
}
When I compiled and ran it using Node, the output was
The decorated class [Function: SampleClass]
. Why didn't I see Hey!
? Can someone help me understand this code? I saved it as
decorators.ts
I compiled it with tsc --target ES5 --experimentalDecorators decorators.ts and then ran node decorators.js
The documentation is too complex for me to decipher
I am completely confused - in Angular we don't have to instantiate a class and everything still works fine, but here we do. Can someone please explain why there's no need to instantiate a class in TypeScript?