Skip to content

Instantly share code, notes, and snippets.

@ericelliott
Created August 15, 2010 02:26
Show Gist options
  • Save ericelliott/524989 to your computer and use it in GitHub Desktop.
Save ericelliott/524989 to your computer and use it in GitHub Desktop.
/**
* Module Pattern Assignment Example
* @author Eric Hamilton
*/
// Assign the return result of an anonymous self executing function to a public variable
var encapsulatedNamespace = (function () {
var privateVar = "Secret stuff",
privateFunction = function () {
var result;
// do something with privateVar
return result;
},
someObject = {
privateMember : "Some private data",
publicMember : privateFunction() // assign the result of the privateFunction() call to publicMember
},
// expose only your public interface to the global scope
publicAPI = {
publicData : someObject.publicMember
};
return publicAPI;
}());
@JoeKanyoko
Copy link

Nice

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment