Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Revealing module pattern
if (typeof DOJ == 'undefined') {
DOJ = {};
DOJ = function () {
var _myPrivateVar = "_myPrivateVar can be accessed only from within DOJ.";
var myPublicProperty = "myPublicProperty is accessible as DOJ.myPublicProperty.";
var _myPrivateMethod = function () {
console.log("_myPrivateMethod can be accessed only from within DOJ.");
return "Returned from _myPrivateMethod";
var myPublicMethod = function () {
console.log("myPublicMethod is accessible as DOJ.myPublicMethod.");
//Within myProject, I can access "private" vars and methods:
//The native scope of myPublicMethod is DOJ; we can
//access public members using "this":
// return public properties and methods
return {
myPublicProperty: myPublicProperty,
myPublicMethod: myPublicMethod
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.