Created
March 2, 2014 17:17
-
-
Save richistron/9309932 to your computer and use it in GitHub Desktop.
Private values inside object clusure
This file contains hidden or 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
/** | |
* 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