Skip to content

Instantly share code, notes, and snippets.

@enoliglesias
Forked from carloscabo/js_module_closure.js
Created March 17, 2016 15:31
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 enoliglesias/c3964c351a6ee0f824e1 to your computer and use it in GitHub Desktop.
Save enoliglesias/c3964c351a6ee0f824e1 to your computer and use it in GitHub Desktop.
JS Module with closure
;(function($, undefined) {
'use strict';
if (typeof window.MY_MODULE_NAME !== 'undefined') {
return;
}
//
// Module general vars
//
var
$document = $(document),
data = {};
//
// Methods
//
function init(params) {
// Method code here
}
function anotherMethod(params) {
// Method code here
}
//
// Modeule events
//
$document.on('change', 'SELECTOR', function(){
})
.on('click', 'SELECTOR', function(){
});
//
// Public methods / properties
//
window.MY_MODULE_NAME = {
init: init,
data: data
};
}(jQuery));
// Usage
// MY_MODULE_NAME.init(params);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment