ns.js
simple javascript namespacing
examples
Create a namespace and its object:
var obj = ns("com.app.someVar", 254);
// obj = 254get a namespace path:
var obj = ns("com.app.someVar") // already created
// obj === 254
var objError = ns("com.app.someOtherVar") // does not exists
// objError === undefinedobscure namepsace
if you wish NOT to attach a namespace to window and obscure it from being global
you may pass as a first parameter 'true' or an exisitng object, your objects will get attached to a
variable under window.___ by default or to the object passed -- if you know of a better way, fork and send pull request
passing true:
var obj = ns(true, "obscured.namespace", 1);
// window.obscured === undefined
// window.___.obscured === [obj]passing an object:
// be sure the object you pass actually exists if not create it
window.mynamespace = window.mynamespace || {};
// ON GLOBAL NAMESPACE
var obj = ns(window.mynamespace, "custom.namespace", 1);
// window.custom === undefined
// window.mynamespace.custom === [obj]
// obj === 1
// OR LOCAL NAMESPACE
var local = {};
var obj = ns(local, "custom.namespace", 1);
// window.local === undefined
// local.custom === [obj]
// obj === 1