Skip to content

Instantly share code, notes, and snippets.

@jeffAwesome
Last active August 29, 2015 14:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jeffAwesome/8936bc595342596219cb to your computer and use it in GitHub Desktop.
Save jeffAwesome/8936bc595342596219cb to your computer and use it in GitHub Desktop.
Javascript Module Pattern
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