3 ms·
Also, I believe TypeScript uses these to transpile classes with public and private properties/methods (can't verify that's still case atm). It's a really neat
by alexanderdmitri 7y ago
Also, I believe TypeScript uses these to transpile classes with public and private properties/methods (can't verify that's still case atm).
It's a really neat pattern imo, I remember it fondly from my JS heavy days :)
- munchbunny 7y agoIt's a useful pattern that I used a lot, though I don't know if I would agree that it's neat. I definitely prefer the explicit annotations or even the python underscore convention.
- Zarel 7y agoNo, while this is sometimes used for private properties/methods, TypeScript never used it. TypeScript's private properties/methods are just compile-time errors, they're still public in the generated code.
- alexanderdmitri 7y agoYou're right[0], which is weird because they got most of the way there. I guess I just assumed since they were leveraging IIFEs this would be a natural use case. I'd be interested in knowing why they didn't actually. According to this[1] exchange on Stack Overflow, the IIFE is used by TypeScript because of other scoping issues (specifically protecting class properties before instantiation and defining interfaces). [0] https://yakovfain.com/2015/06/30/the-private-in-typescript-is-kinda-private/ https://yakovfain.com/2015/06/30/the-private-in-typescript-i... [1] https://stackoverflow.com/questions/56086411/why-does-typescript-pack-a-class-in-an-iife https://stackoverflow.com/questions/56086411/why-does-typesc...