DEV Community

Discussion on: Functional VS Object-Oriented Programming

Collapse
 
stereobooster profile image
stereobooster
Collapse
 
krtb profile image
Kurt Bauer

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 • 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."