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 ...

Get Mastering JavaScript Object-Oriented Programming now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.