Does `decorate` also works for single function?
commonuserlol opened this issue · comments
Just an internal question, as title says. I saw that it works for interfaces (or how const something = {...} called?), but seems it not work for single function, e.g
function asd() {...}
decorate(asd, cache);
decorators can't be applied to single functions (only for class methods/properties) so it will be great to get kinda hack without deps.
You are correct, you can't decorate a top level function.
You could achieve a similar result by:
function foo() {
return 1;
}
function decorate(target) {
const impl = globalThis[target];
globalThis[target] = function () {
return impl() + 1;
}
}
decorate("foo");