Last active
January 21, 2018 09:56
-
-
Save rudimusmaximus/bbfe6a0bba91de6364e7279e9b68853b to your computer and use it in GitHub Desktop.
Completed example .gs to demonstrate 4 level namespacing
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
/**** | |
* 'SEED' THE NAMESPACES | |
*****/ | |
var NAME$PACE1 = (function(ns) { | |
ns.author = "Raul Flores, Jr"; | |
ns.description = "This is an example 4 level namespace." | |
ns.value = "some value"; | |
ns.Enums = { | |
ZERO: 0, | |
ONE: 1, | |
TWO: 2 | |
}; | |
ns.doSomething = function () { | |
return 100; | |
}; | |
return ns; | |
})(NAME$PACE1 || {}); | |
/**** | |
* 'POPULATE' THE NAMESPACE - define additional methods and properties | |
* Nested level functions | |
* to 'nest' a nameNAME$PACE use the pattern, just declare and pass the nested object when defining the immediately invoked function | |
*****/ | |
(function (nested) { | |
/** | |
* notes on what was done | |
* @return {string} returns statement in string | |
*/ | |
nested.subsetOfFunctions1.doSomething = function () { | |
return "This is the something that was done."; | |
}; | |
return nested; | |
})(NAME$PACE1.GroupingA = {subsetOfFunctions1:{}}); | |
function testIt(){ | |
var x = NAME$PACE1.GroupingA.subsetOfFunctions1.doSomething(); | |
Logger.log(x); | |
Logger.log(JSON.stringify(NAME$PACE1)); | |
} |
Done. see final revised gist.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
REWRITING FOR MY OWN purposes.