Created
July 25, 2012 19:26
-
-
Save keithelliott/3178039 to your computer and use it in GitHub Desktop.
use a javascript namespace
This file contains hidden or 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
//uses the following syntax to create an object with private properties | |
// and functions. You expose the properties and functions you need publicly in the | |
// return object.... The immediate function allows us to have private scope for | |
// certain things | |
// Create a new namespace | |
CHATHAM.namespace('CHATHAM.utils.gridmgr'); | |
CHATHAM.utils.gridmgr = (function(){ | |
function doSomethingPrivately() { | |
return "I am private"; | |
} | |
function doItPublic() { | |
return "I am public"; | |
} | |
return { | |
doIt: doItPublic | |
}; | |
}()); | |
//uses the following syntax to create an function on the namespace | |
//The immediate function allows us to have private scope for | |
//certain things | |
// Create a new namespace | |
CHATHAM.namespace('CHATHAM.utils.Grid'); | |
CHATHAM.utils.Grid = (function(global){ | |
// dependencies | |
var grdMgr = CHATHAM.util.gridmgr, | |
Constr; | |
Constr = function { | |
// add properties etc | |
}; | |
Constr.prototpye = { | |
constructor: CHATHAM.util.Grid, // could be helpful to know the namespace | |
version: "0.5" // in future we could add versions to our stuff | |
}; | |
// return the contructor | |
// to be assigned to the namespace | |
return Constr; | |
})(this); //we can make this module self contained by passing in the global 'this' | |
// context namespace and assigning it to global |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment