Skip to content

Instantly share code, notes, and snippets.

@jaseemabid
Created October 26, 2011 16:39
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jaseemabid/1316930 to your computer and use it in GitHub Desktop.
Save jaseemabid/1316930 to your computer and use it in GitHub Desktop.
Private variables in JavaScript
console.log("Private variables in JavaScript");
var a = (function(){
return obj = {
pub : 'public data',
getSecret : function() {
var secret = 'my secret';
return secret;
}
};
})();
console.log("The object (No reference to private data) : ");
console.log(a);
console.log("Private data retrived with get functions : ");
console.log(a.getSecret());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment