Skip to content

Instantly share code, notes, and snippets.

@justinobney
Last active December 15, 2015 10:59
Show Gist options
  • Select an option

  • Save justinobney/5250221 to your computer and use it in GitHub Desktop.

Select an option

Save justinobney/5250221 to your computer and use it in GitHub Desktop.
JS Closure Beginner Example
var MyApp = MyApp || {};
(function(app) {
var count = 0;
app.add = add;
app.getCount = getCount;
function add() {
count++;
}
function getCount() {
console.log(count);
}
})(MyApp);
MyApp.echoCount = function() {
console.log(count);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment