Skip to content

Instantly share code, notes, and snippets.

View SeanCPP's full-sized avatar
🏠
Working from home

Sean Franklin SeanCPP

🏠
Working from home
View GitHub Profile
@SeanCPP
SeanCPP / TrueEncapsulationInJS.md
Last active March 26, 2023 04:17
True Encapsulation in JavaScript: How to Achieve private Accessibility

True Encapsulation in JavaScript

How to achieve "private" in a dynamic language

If you're developing in a dynamically-typed language like JavaScript or Python, you may be dearly missing our friend "private" from statically-typed languages like C#, Java, and C++.

I'm sure plenty of developers know about this already, but I feel like no one ever talks about this. In all my years of studying programming, every time I've searched for how to achieve true encapsulation in JavaScript, the same answer always appears:

You can't.