Last active
July 20, 2021 17:52
-
-
Save iknowkungfoo/dbb79634f24a28e5b70d to your computer and use it in GitHub Desktop.
JavaScript Revealing Module Template with jQuery setup
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
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