Last active
January 2, 2016 04:19
-
-
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
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
// 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