Last active
August 29, 2015 14:21
-
-
Save jeffAwesome/8936bc595342596219cb to your computer and use it in GitHub Desktop.
Javascript 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 IceIceBaby = (function(window, $, undefined) { | |
/* | |
For clarity when you see this being referenced, in this instance its referencing | |
a new object that was created when the new keyword was called. The new object | |
will have the init function and the stop function on it. | |
*/ | |
var VanillaIce = function() { | |
// public methods | |
this.init = function() { | |
console.log(this.publicData); | |
}; | |
// public method but pulls some private data | |
this.stop = function() { | |
console.log(iceSolvesProblem) | |
}; | |
this.publicData = "stop collaborate and listen"; | |
return this; | |
}; | |
// Private Data | |
var iceSolvesProblem = "If there was a problem, Yo, I'll solve it!"; | |
return VanillaIce; | |
}(window, $)); | |
// vanilla Ice helps you understand javascript | |
var iceModule = new IceIceBaby(); | |
iceModule.init(); // logs public data "stop collaborate and listen" | |
iceModule.stop(); // logs private data "If there was a problem, Yo, I'll solve it!" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment