Closed commonuserlol closed 10 months ago
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");
Now im dealing with applying real decorator to it. My ts knowledge is bad and i didnt found anything in google. For example your lazy
, how i can apply it to single function? I did workaround for my cache
but it requires separate functions. i know that its kinda offtop but any idea?
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
decorators can't be applied to single functions (only for class methods/properties) so it will be great to get kinda hack without deps.