Skip to content

Instantly share code, notes, and snippets.

@cesarmiquel
Last active August 29, 2015 13:57
Show Gist options
  • Save cesarmiquel/9709930 to your computer and use it in GitHub Desktop.
Save cesarmiquel/9709930 to your computer and use it in GitHub Desktop.
This is a basic pattern for an extensible JavaScript module. This example is based off: http://www.adequatelygood.com/JavaScript-Module-Pattern-In-Depth.html where you can find several more snippets.
var UTIL = (function (my, $) {
// private variables
var privateVariable = 1;
// private methods
function privateMethod() {
// ...
}
// public variables
my.moduleProperty = 1;
// public methods
my.moduleMethod = function () {
// You get access to jQuery
$('document').bind( ... );
};
return my;
}(UTIL || {}, jQuery));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment