Last active
December 19, 2015 07:39
-
-
Save robatron/5919951 to your computer and use it in GitHub Desktop.
JavaScript Module Pattern Example with "Passive Attachment"
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
/** JavaScript Module Pattern Example with "Passive Attachment" | |
*/ | |
(function( | |
win, | |
doc, | |
$, | |
a, | |
b | |
){ | |
// "Passively attach" your new module to global through your namespace, | |
// i.e., attach only if your module name doesn't already exist to avoid | |
// clobbering existing modules with the same name | |
my.namespace.c = my.namespace.c || function(){ | |
var self = this; | |
// Create "private" module properties | |
var privPropA = ...; | |
var privPropB = function(){...}; | |
// Create "public" module properties | |
self.pubPropA = ...; | |
self.pubPropB = function(){...}; | |
// Use "imported" modules | |
$(doc).ready(function(){...}) | |
a(); | |
b(); | |
return self; | |
}; | |
})( | |
window, | |
document, | |
jQuery, | |
my.namespace.a, | |
my.namespace.b | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment