re: Emulating "Private" Variables in JavaScript with Closures and Factory Functions VIEW POST

re: I wonder what the memory performance is like compared to this: const privates = new WeakMap() class Animal { constructor(name, job) { priv...

I'm not sure myself, honestly. I'd love to know. When I have the time, I'll try to create a rigorous experiment for this using the DevTools Memory tools.

If I were to make an educated guess, I'd say the difference in memory efficiency would be negligible.


How funny is it, though, that this method is still using closures, the 5 functions capturing privates :D

It makes you realize that even though closures are so ubiquitous in JavaScript, not everyone truly understands it.

Code of Conduct Report abuse