Determine if a namespace/variable-name exists
Check for namespace existence in your environment variables and objects before writing to them.
Guess if "Book1.chapter22.paragraph37" exists without provoking errors and retrieve/send data if it exists with simplest JS expressions.
Call syntax:
isNS( [string], [num] );
Example:
var nsresult =
isNS( "Book1.chapter22.paragraph37", -1 );
if( nsresult[0] ){ send( nsresult[1] ) else notify( nsresult[4], nsresult[2] ) };...
etc, etc.
Omit secondary argument (function-return modifier) to get a Boolean.
(Using 0, false, or undefined keyword has the same effect.)
isNS( "myObject.property.subProperty.myMethod" );
_> Boolean : true/false
Modifier Possible values:
_> -1; (0|false|undefined); ( 1|true ); 2; 3 or 4.
Description:
(-1 ) _> returns array object containing complete inoculation.
( 0 ) _> optional; returns Boolean: true (if complete NS chain exist) : false (if it's broken).
( 1 ) _> if NS query exists, case true: returns the existing value; if not, case false: returns the last valid context if any, or the global object if root doesn't exist.
( 2 ) _> returns an array of existing namespaces in the argument query.
( 3 ) _> returns an array containing all specified namespaces.
( 4 ) _> returns the original query string.
*NS - stands for already familiar "Namespace" initials.
[This makes but a tinny cluster on some real A.I., Yet -a very important one!]