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.html
and check the console - For server: Run
node test.js
and watch the output
In server mode namespace.js
will register itself under global
scope so you may use it globally without any hassle.
npm
package