A meta-closure approach
The basic idea of the previous approach builds on the nature of closure. The constructor's environment is protected by default and remains accessible from the inside of the constructor itself even after it terminates. However, since the closure is created when the constructor is called, each object instance needs to have both private data and privileged methods defined inside the constructor context. An ideal solution should be one that protects private data letting them be accessible from outside the constructor's closure. This should be a sort of meta-closure that offers an extra level of protection-a closure accessible from outside the object constructor by prototype members still hiding private data of the resulting object. This meta—closure can be built using an Immediately Invoked Function Expression (IIFE).
Immediately invoked function expressions
An IIFE, also called a self-executing anonymous function, is a JavaScript expression involving...