▲ | jfagnani 7 days ago | |||||||
Decorators are the only way to metaprogram over class fields in JS. Otherwise they're not even detectable on the prototype. We use them to make fields reactive mostly, and I love how declarative they are. But we use them sparingly. I personally don't love how some libraries try to put a lot of things into decorators that could have been standard class features, like a static field or a method. edit: As mentioned by skrebbel, decorators are optional. Every decorator has a simple plain-JS way of doing it. Event reactive properties: https://lit.dev/docs/components/properties/#declaring-proper... We also put a lot of effort into making all of our documentation and playground samples on lit.dev available in both JavaScript and TypeScript with decorators. There's a switch that will change everything on the site from JS to TS globally. | ||||||||
▲ | epolanski 7 days ago | parent | next [-] | |||||||
> Decorators are the only way to metaprogram over class fields in JS. I can think about few other ways, such as using higher order functions/classes, using getOwnPropertyDescriptor or doing stuff at construction. > As mentioned by skrebbel, decorators are optional This is not a pro, it's a con. The more ways there are to achieve the same result the more inconsistent projects become IRL. Also, do you really want to metaprogram at all? What's the huge benefit of that approach? | ||||||||
| ||||||||
▲ | brazukadev 7 days ago | parent | prev [-] | |||||||
> Decorators are the only way to metaprogram over class fields in JS. No, they are not. Decorators don't even exist in JavaScript. Stop assuming typescript is Javascript or even worse, that everybody is on board. > There's a switch that will change everything on the site from JS to TS globally. Lol. |