© 2005 Goetz Heller
Table of Contents Description Source Code Copyright Note back
// ex.1a: create a simple namespace explicitely (not recommended)
document.write('<'+'h4>Create Namespace <'+'em>a<'+'/em><'+'/h4>');
_a = function() {};
_a.prototype.isNameSpace = function() { return true; };
_a.prototype.isClass = function() { return false; };
_a.prototype.toString = function() { return 'a'; };
a = new _a();
if (core.isNameSpace('a')) {
document.write('Namespace <'+'em>a<'+'/em> created.<'+'br/>');
} else {
document.write('Failed to verify namespace <'+'em>a<'+'/em>.<'+'br/>');
}
// ex.1b: checking for non-existing namespace
document.write('<'+'h4>Test for Existence of a Namespace <'+'em>i<'+'/em><'+'/h4>');
if (core.isNameSpace('i')) {
document.write('Namespace <'+'em>i<'+'/em> exists.<'+'br/>');
} else {
document.write('Failed to verify namespace <'+'em>i<'+'/em>.<'+'br/>');
}
// ex.2: create a nested namespace inside a explicitly (not recommended)
document.write('<'+'h4>Create Namespace <'+'em>a.b<'+'/em><'+'/h4>');
if (!core.isNameSpace('a')) {
document.write('Cannot verify namespace <'+'em>a.b<'+'/em> since namespace <'+'em>a<'+'/em> does not exist.<'+'br/>');
} else {
a._b = function() {};
a._b.prototype.isNameSpace = function() { return true; };
a._b.prototype.isClass = function() { return false; };
a._b.prototype.toString = function() { return 'a.b'; };
a.b = new a._b();
if (core.isNameSpace('a')) {
document.write('Namespace <'+'em>a.b<'+'/em> created.<'+'br/>');
} else {
document.write('Failed to verify namespace <'+'em>a.b<'+'/em>.<'+'br/>');
}
}
// ex.3: create a name space on the fly (recommended)
document.write('<'+'h4>Verify Namespace <'+'em>c<'+'/em><'+'/h4>');
if (core._verifyNameSpace('c')) {
document.write('Namespace <'+'em>' + c + '<'+'/em> o.k.<'+'br/>');
} else {
document.write('Failed to verify namespace <'+'em>c<'+'/em>.<'+'br/>');
}
// ex.4: create a nested name space inside c on the fly (recommended)
document.write('<'+'h4>Verify Namespace <'+'em>c.d<'+'/em><'+'/h4>');
if (core._verifyNameSpace('c.d')) {
document.write('Namespace <'+'em>' + c.d + '<'+'/em> o.k.<'+'br/>');
} else {
document.write('Failed to verify namespace <'+'em>c.d<'+'/em>.<'+'br/>');
}
// ex.5: create a nested namespace inside c.d on the fly (recommended)
document.write('<'+'h4>Verify Namespace <'+'em>c.d.e<'+'/em><'+'/h4>');
if (core._verifyNameSpace('c.d.e')) {
document.write('Namespace <'+'em>' + c.d.e + '<'+'/em> o.k.<'+'br/>');
} else {
document.write('Failed to verify namespace <'+'em>c.d.e<'+'/em>.<'+'br/>');
}
// ex.6a: create a nested namespace and all its ancestors on the fly (recommended)
document.write('<'+'h4>Verify Namespace <'+'em>s.t.u.v.w.x.y.z<'+'/em><'+'/h4>');
if (core._verifyNameSpace('s.t.u.v.w.x.y.z')) {
document.write('Namespace <'+'em>' + s.t.u.v.w.x.y.z + '<'+'/em> o.k.<'+'br/>');
} else {
document.write('Failed to verify namespace <'+'em>s.t.u.v.w.x.y.z<'+'/em>.<'+'br/>');
}
// ex.6b: check for existence of containing namespace
document.write('<'+'h4>Test for Existence of Namespace <'+'em>s.t.u.v<'+'/em><'+'/h4>');
if (core.isNameSpace('s.t.u.v')) {
document.write('Namespace <'+'em>'+s.t.u.v+'<'+'/em> exists.<'+'br/>');
} else {
document.write('Failed to verify namespace <'+'em>s.t.u.v<'+'/em>.<'+'br/>');
}
// ex.7: create a shortcut for an existing namespace (recommended)
document.write('<'+'h4>Create Shortcut for Namespace <'+'em>'+s.t.u.v+'<'+'/em><'+'/h4>');
var D = core.createShortCut('s.t.u.v');
if (D.isNameSpace()) {
document.write('Shortcut <'+'em>D<'+'/em> for Namespace <'+'em>' + D + '<'+'/em> created.<'+'br/>');
} else {
document.write('Failed to verify shortcut for namespace <'+'em>s.t.u.v<'+'/em>.<'+'br/>');
}
// ex.8: create a shortcut and the namespace it stands for in one step (recommended)
document.write('<'+'h4>Create Shortcut <'+'em>O<'+'/em> And Namespace <'+'em>k.l.m.n.o<'+'/em> in One Step<'+'/h4>');
var O = core.createShortCut('k.l.m.n.o');
if (O.isNameSpace()) {
document.write('Namespace <'+'em>' + O + '<'+'/em> o.k.<'+'br/>');
} else {
document.write('Failed to verify namespace <'+'em>k.l.m.n.o<'+'/em>.<'+'br/>');
}