Skip to content

Instantly share code, notes, and snippets.

@GerryFudd
Created March 5, 2015 19:11
Show Gist options
  • Save GerryFudd/16e31873381c16732942 to your computer and use it in GitHub Desktop.
Save GerryFudd/16e31873381c16732942 to your computer and use it in GitHub Desktop.
Example of a module pattern
var module = (function(input) {
var localVariable = 4;
var my = {};
my.shout = function() {
console.log('module.value is ' + this.value);
console.log('input is ' + input);
console.log('globalVariable is ' + globalVariable);
};
my.method = function() {
my.value = localVariable;
input = 8 / my.value;
return [my.value, input];
};
return my;
})(globalVariable);;
var globalVariable = 0;
module.value = 0;
module.shout();
module.method();
module.shout();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment