introspect-namespace
Provides rudimentary namespacing DSL.
- Install
- API
newContext()
: Create a new namespacing contextnamespace.root
: Get the context's root namespacenamespace.isNamespace
: Namespace checking predicatenamespace()
: Get the current namespacenamespace(String)
: Get/Create a namespacenamespace(String, Function)
: Assign namespace membersnamespace(String, Object)
: Assign namespace members
Install
npm install introspect-namespace
API
newContext()
: Create a new namespacing context
var namespace = ;
var namespace = namespace;
Returns a new namespace function, with the same attributes as the default one. The namespaces defined with this method are all completely independent.
namespace.root
: Get the context's root namespace
The root namespace is also the default namespace.
namespace.isNamespace
: Namespace checking predicate
var isNs = namespaceisNamespace; var ns = ; tobetrue; tobetrue;
This function returns false
for namespaces defined in a different context.
namespace()
: Get the current namespace
Calls to namespace(String, Function)
modify a stack of namespaces.
In order to get the currently used namespace, call namespace()
.
By default, it will return namespace.root
.
namespace(String)
: Get/Create a namespace
Create inexisting namespaces:
var namespace = ; var rootNs = namespaceroot; var ns = ; tobe;
Fetching existing namespaces:
ns = ; tobe; ns = ; tobe;
Even fetching namespace member values:
ns = ; nstestValue = 23; tobe;
namespace(String, Function)
: Assign namespace members
Allows to define members for the namespaces in nested functions.
var namespace = ; var rootNs = namespaceroot; var someNs = ; tobe; ; tobe;
Trying to add already existing members throws an Error.
namespace(String, Object)
: Assign namespace members
Add members directly:
var namespace = ; var rootNs = namespaceroot; ; tobe; tobe;