JavaScript does not come with dedicated means for managing private data for an object. This post describes five techniques for working around that limitation:
* Instance of a constructor – private data in environment of constructor
* Singleton object – private data in environment of object-wrapping IIFE
* Any object – private data in properties with marked names
* Any object – private data in properties with reified names
* Single method – private data in environment of method-wrapping IIFE
The following sections explain each technique in more detail.
Required knowledge: While everything is explained relatively slowly, you should probably be familiar with environments and IIFEs [1] and with inheritance and constructors [2].
Your new post is loading...