"Private" Variables with Closures and Factory Functions

Erik Aybar
InstructorErik Aybar

Share this video with your friends

Send Tweet

By making use of closures and lexical scope, we can achieve "private" properties by returning objects with methods from a factory function. By defining our desired "private" variables within our factory function and accessing these variables from within our returned object's methods we create a closure and maintain unique, separate references to our "private" variables.