The ability to reply to discussions is limited to PRO members. Want to join in the discussion? Click here to subscribe now.

"Private" Variables with Closures and Factory Functions

"Private" Variables with Closures and Factory Functions

3:01
By making use of [closures and lexical scope](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Closures), 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.
Watch this lesson now
Avatar
egghead.io

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.

HEY, QUICK QUESTION!
Joel's Head
Why are we asking?