Created
October 26, 2011 16:39
-
-
Save jaseemabid/1316930 to your computer and use it in GitHub Desktop.
Private variables in JavaScript
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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