Skip to content

Instantly share code, notes, and snippets.

@brainded
Last active January 2, 2016 04:19
Show Gist options
  • Save brainded/8249732 to your computer and use it in GitHub Desktop.
Save brainded/8249732 to your computer and use it in GitHub Desktop.
Because I always forget some of the basic JS patterns I have used over the last 2 years
// create 'bobsburgers' if it is not already declared
var bobsburgers = bobsburgers || {};
// create a new namespace under 'bobsburgers'
bobsburgers.buyburgers = (function (locallyScopedVariable) { //globallyScopedVariable got aliased to locallyScopedVariable
//define a function that is locally scoped
var _localFunction = function (params) {
//do something interesting
};
//iffy - see more here: http://benalman.com/news/2010/11/immediately-invoked-function-expression/
(function initialize() {
//do something immediately
})();
return {
publicFunction: _localFunction
};
})(globallyScopedVariable);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment