Skip to content

Instantly share code, notes, and snippets.

@carloscabo
Last active March 17, 2016 15:34
Show Gist options
  • Save carloscabo/9144d3cc839a6ba852ac to your computer and use it in GitHub Desktop.
Save carloscabo/9144d3cc839a6ba852ac 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