DEV Community

loading...

Discussion on: Functional VS Object-Oriented Programming

Collapse
krtb profile image
Kurt Bauer Author

Thanks for the heads up! I did some more research after you mentioned this and found a great article that talks about achieving "pseudo-encapsulation" through the use of factory functions and closures in JS for example. Really cool stuff

Collapse
stereobooster profile image
stereobooster

Why "pseudo-" though? It can hide variables the same way as class private fields.

Thread Thread
krtb profile image
Kurt Bauer Author • Edited

Hmm, well according to his article he was saying it wasn't natively supported, in JS at least

"By far one of the biggest anomalies of JavaScript is it’s inability to natively support encapsulation.

The scoping system was introduced with TypeScript, which is a superset of JavaScript. But unfortunately its not a clear victory yet since, while it does give you a warning, TypeScript code still compiles and runs even when you access the private variables."