Skip to content

Instantly share code, notes, and snippets.

@iknowkungfoo
Last active July 20, 2021 17:52
Show Gist options
  • Save iknowkungfoo/dbb79634f24a28e5b70d to your computer and use it in GitHub Desktop.
Save iknowkungfoo/dbb79634f24a28e5b70d to your computer and use it in GitHub Desktop.
JavaScript Revealing Module Template with jQuery setup
NameSpace.moduleName = function($) {
// Private variable, global to the module.
var _foo;
// Private variable, global to the module.
// Will represent a jQuery object.
var $_bar;
// Constructor
var init = function() {
// Define global, module private variables.
_foo = 'Hello';
$_bar = $('#someThing');
}
var privateFunction = function() {
// Function is private to the module.
// Can't be called externally w/o public definition via return{}.
}
// Call constructor.
$(document).ready( init );
return {
publicFunction: function() {
// Publically accessible function.
// NameSpace.moduleName.publicFunction();
},
// Allow public access to privateFunction()
// NameSpace.moduleName.anotherPublic();
anotherPublic: privateFunction
}
}(jQuery);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment