Skip to content

Instantly share code, notes, and snippets.

@richistron
Created March 2, 2014 17:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save richistron/9309932 to your computer and use it in GitHub Desktop.
Save richistron/9309932 to your computer and use it in GitHub Desktop.
Private values inside object clusure
/**
* Object with hidden values
*/
var ObjectClosure = (function(){
var privateValue = "hello there!!";
return {
getValue: function(){
return privateValue;
},
setValue: function(newValue){
return privateValue = newValue;
},
};
})();
// example
console.log(ObjectClosure)
console.log(ObjectClosure.getValue())
ObjectClosure.setValue('Hello ese')
console.log(ObjectClosure.getValue())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment