DEV Community

Discussion on: JS interview in 2 minutes / Encapsulation (OOP)

Collapse
 
scott_yeatts profile image
Scott Yeatts

While it's true that JS doesn't have private properties, but this is a solved problem (No Typescript necessary!)

Use the Revealing Module design pattern, and you can have a public/private API for your module.

That said, I also believe JavaScript is trending more towards the Functional Programming world, and I'm an advocate for that direction. That doesn't mean that OOP is outdated or not something to learn, just that I don't think it's the best fit for most (but not all) JS applications.

I can't wait for the industry to reach a better balance between functional approaches, which are GREAT for stateless, event driven actions (IE: Your typical microservices web backend) and OOP which are much better suited for stateful, context dependent actions (Like you might see in an application designed to run independently without API support, like a desktop app or a game).

Both are useful, but I've seen a lot of people trying to use one or the other as a hammer, when all they have are a box of screws!

Collapse
 
hexnickk profile image
Nick K

Thanks for the comment! I've added a note about the Revealing Module pattern to the post itself and mentioned you πŸ™ Thanks again!

Both are useful, but I've seen a lot of people trying to use one or the other as a hammer when all they have are a box of screws!

Totally agree with you, the right tool, for the right need!