In ES5, you can use property descriptors to limit access to certain properties, but you can’t do anything like this in ES3. So how do you create private properties that no one is allowed to touch?
The solution is to use a closure and not expose the variables you want to keep private. These will not be exactly private properties of an object, but they will be private nevertheless.
An example of using a closure for privacy was discussed in Immediate Functions. But the topic is worth reviewing and expanding. A common pattern of using a closure to define an object is like this:
At first sight, the end result is not different ...