ns

Organize your code in namespaces

namespace

This package provides namespaces for your nodejs or browser app. It help's you organizing your code without writing wired variable constructs and helper objects.

npm install ns

then require the module in your application code

var namespace = require('ns');

or in the browser simply add the namespace.js to your script sources

<script type="text/javascript" src="namespace.js"></script>

Define a new namespace and assign a function

namespace('company.hello.world', function() {
  console.log('Hello World');
});

now you can run the function in any of your scripts which have access to the same window/global object.

A namespace can contain everything. Objects, functions and even variables - string, integer, float, ...

namespace('company.hello.world')(); // => Hello World 

When you assign any kind of variable, object or function to a namespace it won't be stored in the namespace scope. It is attached on nodejs to the global var and in your local browser to window. These variables are reachable for all code in your application.

So you may access the namespace defined as follows:

namespace('hello.world', "Hello World");

in this way:

global.hello.world // => Hello World 
window.hello.world // => Hello World 

The project is licensed under the conditions of the MIT licence.