Created
March 26, 2014 08:39
-
-
Save hansmaad/9778949 to your computer and use it in GitHub Desktop.
Template for Revealing Module Pattern with submodule
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
(function(module, undefined) { | |
var privateProb = "Private"; | |
var privateFunc = function(prob) { | |
return prob + privateProb; | |
}; | |
module.publicProb = "Hello Module"; | |
module.publicFunc = function() { | |
return privateFunc(module.publicProb); | |
}; | |
})(window.module = window.module || {}); | |
(function(module, sub, undefined) { | |
var Custom = function(x, y) { | |
this.x = x; | |
this.y = y; | |
}; | |
Custom.prototype.sum = function() { | |
return this.x + this.y ; | |
}; | |
sub.custom = function(x, y) { | |
return new Custom(x, y); | |
}; | |
}) | |
(window.module = window.module || {}, | |
window.module.sub = window.module.sub || {}); | |
console.log(module.publicFunc()); | |
var c = module.sub.custom(1, 2); | |
console.log(c.sum()); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment