Small yet effective Javascript namespace management
Compatible with browser and server (node.js)
namespace.js("com.example.portal");
console.log(com.example.portal);
namespace.js("com.example.portal.constants").CONSTANT_VALUE = 123;
console.log(com.example.portal.constants.CONSTANT_VALUE);Check test.js for more
- Copy
namespace.js - Include in your html
<script src="namespace.js"></script>
- Copy
namespace.js - Include in your code
require("./namespace.js");
- For browser: Run
test.htmland check the console - For server: Run
node test.jsand watch the output
In server mode namespace.js will register itself under global scope so you may use it globally without any hassle.
npmpackage