public

JavaScript Module Pattern Example with "Passive Attachment"

  • Download Gist
passive-attach-module-pattern-example.js
JavaScript
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37
/** 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
)

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.