Created
November 20, 2012 16:08
-
-
Save esgy/4118854 to your computer and use it in GitHub Desktop.
js: 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 someModule = function(){ | |
//private attributes | |
var privateVar = 5; | |
//private methods | |
var privateMethod = function(){ | |
return 'Private Test'; | |
}; | |
return { | |
//public attributes | |
publicVar : 10, | |
//public methods | |
publicMethod : function(){ | |
return ' Followed By Public Test '; | |
}, | |
//let's access the private members | |
getData : function(){ | |
return privateMethod() + this.publicMethod() + privateVar; | |
} | |
} | |
}(); //the parens here cause the anonymous function to execute and return | |
someModule.getData(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment