Created
August 15, 2010 02:26
-
-
Save ericelliott/524989 to your computer and use it in GitHub Desktop.
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
/** | |
* 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; | |
}()); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Nice