Created
September 9, 2013 20:02
-
-
Save scarfacedeb/6500740 to your computer and use it in GitHub Desktop.
My basic modular pattern for javascript files
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
var Module = (function(document, window, $){ | |
var self = {}, | |
// DOM/jQuery | |
$document = $(document), | |
$window = $(window), | |
// flags | |
// private functions | |
bindEvents, | |
assignDomVariables; | |
bindEvents = function(){ | |
$document.on( 'ready page:change', assignDomVariables ); | |
$document.on( 'ready page:change', function(){ | |
}); | |
$document.on( 'page:receive', self.destroy ); | |
}; | |
// assign DOM-dependent variables | |
assignDomVariables = function(){ | |
}; | |
// module settings | |
self.settings = { | |
}; | |
self.init = function( settings ){ | |
if ( settings ) { | |
$.extend( {}, self.settings, settings ); | |
} | |
bindEvents(); | |
}; | |
self.destroy = function(){ | |
$window.off('.module'); | |
}; | |
return self; | |
})(document, window, jQuery); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment