Skip to content

Instantly share code, notes, and snippets.

@jbuffin
Last active August 29, 2015 14:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jbuffin/90ba3cb368f2b419c70b to your computer and use it in GitHub Desktop.
Save jbuffin/90ba3cb368f2b419c70b to your computer and use it in GitHub Desktop.
Library pattern
(function MyLibrary(window) {
var privateVar;
function init() {
// do whatever is necessary here
privateVar = 'initial state';
}
function publicMethod() {
// this function is exposed
}
function privateMethod() {
// this function is protected in the IIFE
}
window.MyLibrary = {
init : init,
publicMethod : publicMethod
};
})(window);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment