Created
March 5, 2015 19:11
-
-
Save GerryFudd/16e31873381c16732942 to your computer and use it in GitHub Desktop.
Example of a module pattern
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
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