Skip to content

Instantly share code, notes, and snippets.

@jeffsheets
Created August 23, 2012 15:13
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 jeffsheets/3437635 to your computer and use it in GitHub Desktop.
Save jeffsheets/3437635 to your computer and use it in GitHub Desktop.
JS Module Pattern
//From https://github.com/sjurgemeyer/GR8-US-2012/blob/master/Mobile-and-Grails-ZachLendon/Mobile-and-Grails-ZachLendon.pdf
var module = (function () {
// private variables and functions
var foo = 'bar';
// constructor
var module = function () {
};
// prototype
module.prototype = {
constructor: module,
something: function () {
}
};
// return module
return module;
})();
var my_module = new module();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment