OK, I admit it: it'd be convenient if classes could have decorators on methods. Memoization of async methods would be so much cleaner and more reusable if we had them.

@mauve I recently switched from TypeScript to Java and I am such a fan of Java’s annotations. IMO metaprogramming is Good Actually, and full annotations (like the JavaScript decorators were initially proposed as) are a way to get it that’s sometimes more palatable than full macros.

Follow

@jnkrtech Real! Right now you can kind of cheese it by defining a property thats set to a arrow function which you can wrap in whatever.

```
class foo {
example = memoize(async (args) => {etc})
}
```

A bit more gross to read IMO. I think you could also mess with the class prototype?

· · Web · 1 · 0 · 0

@mauve I have seen people productively do stuff involving higher-order classes for things like this but I think it’s a bit fraught. Like you can absolutely make a function that takes a class and an array of method names to modify and gives you back a modified class, but I’ve been bit hard by how incomprehensible the results can be when I didn’t know the secret.

Sign in to participate in the conversation
Mauvestodon

Escape ship from centralized social media run by Mauve.