Ignoring the potential nightmare, pain, and death this might create for a moment... Is there any way for a function to detect if it is being invoked as a decorator from within the function itself?
The idea would be to export something that can be used either as a decorator or as a function on its own.
Take this simplified example:
function Foo() {
const isInvokedAsDecorator = ???
// do some common stuff
if (isInvokedAsDecorator) {
return target => {
// do some decorator stuff...
}
} else {
// do some non-decorator stuff...
}
}
@Foo()
class Test {
}
Foo()
In your case, I see two things you can do. First is just add an argument as :
But you can change also change like this :