Created
March 1, 2012 04:09
-
-
Save gwokae/1947216 to your computer and use it in GitHub Desktop.
A simple Javascript Module Pattern
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
var myObject = (function(){ | |
var _private = { | |
someVar: "This is private", | |
privateFunction = function(){ /* do-something*/ }; | |
} | |
return { | |
publicVar : "This is public", | |
publicFunction : function(){ | |
/*do-something*/ | |
}, | |
getSomeVar: function(){ | |
return _private.someVar; | |
} | |
} | |
}()); | |
myObject._private /* undefined */ | |
myObject.getSomeVar() /* returns "This is private" */ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment