[ascoders] Re: Namensräume
- From: "Andreas Hucks" <andreas@xxxxxxxxxxxx>
- To: <ascoders@xxxxxxxxxxxxx>
- Date: Thu, 27 Mar 2003 15:53:32 +0100
Hallo zusammen,
hab das jetzt mal zusammengebaut. Es wird jetzt doch NUR in den aktivierten
Namensräumen gesucht - denke, das ist näher am Java-Verhalten, wo ja auch
nur importierte Packages durchsucht werden. Statt "import" beutzt man jetzt
"AsSelectPackage (package1, [...], [package_n])". Die ausgewählten
Namensräume bleiben bis zum nächsten Aufruf von AsSelectPackage aktiv. Man
kann das ganze jederzeit durch Aufruf von AsSelectPackage(), d.h. ohne
Argumente, abschalten.
_global.ASNamespaces = new Array();
ASNamespaces._activeNameSpaces = new Array();
_global.AsSetupPackage = function(path) {
var a = path.split('.');
var o = _global;
var currentPath = a[0];
for (var i = 0; i < a.length; i++) {
var name = a[i];
if (o[name] == undefined) {
o[name] = new Object();
}
o = o[name];
ASNamespaces[currentPath] = o;
if (i < a.length - 1) {
currentPath += "." + a[i + 1];
}
}
}
_global.AsSelectPackage = function() {
ASNamespaces._activeNameSpaces = new Array();
for (var i = 0; i < arguments.length; i++) {
ASNamespaces._activeNameSpaces.push(arguments[i]);
}
}
_global.__resolve = function(c) {
for (var i = 0; i < ASNamespaces._activeNameSpaces.length; i++) {
if (typeof ASNamespaces[ASNamespaces._activeNameSpaces[i]][c] ==
"function") {
return
ASNamespaces[ASNamespaces._activeNameSpaces[i]][c];
}
}
return null;
}
// -------------- test --------------
AsSetupPackage("test.blahfasel");
AsSetupPackage("anotherTest");
_global.test.FirstTestClass = function(x) {
trace("constructor of test.FirstTestClass, parameter: " + x);
}
_global.test.blahfasel.TestClass = function(x) {
trace("constructor of test.blahfasel.TestClass, parameter: " + x);
}
_global.test.blahfasel.AnotherTestClass = function(x) {
trace("constructor of test.blahfasel.AnotherTestClass, parameter: " +
x);
}
_global.anotherTest.YetAnotherTestClass = function(x) {
trace("constructor of anotherTest.TestClass, parameter: " + x);
}
AsSelectPackage("test.blahfasel", "test");
var test = new FirstTestClass(1); // "constructor of
test.FirstTestClass, parameter: 1"
var test = new TestClass(2); // "constructor of
test.blahfasel.TestClass, parameter: 2"
var test = new AnotherTestClass(3); // "constructor of
test.blahfasel.AnotherTestClass, parameter: 3"
var test = new YetAnotherTestClass(4); // nix, wird nicht gefunden
var test = new anotherTest.YetAnotherTestClass(5); // "constructor of
anotherTest.TestClass, parameter: 5"
------------------------------------------------------
Archiv : http://www.freelists.org/archives/ascoders/
Optionen : http://www.freelists.org/list/ascoders
------------------------------------------------------
- Follow-Ups:
- [ascoders] Re: Namensräume
- From: Ralf Siegel
- References:
- [ascoders] Re: Namensräume
- From: Andreas Hucks
Other related posts:
- » [ascoders] Namensräume
- » [ascoders] Re: Namensräume
- » [ascoders] Re: Namensräume
- » [ascoders] Re: Namensräume
- » [ascoders] Re: Namensräume
- » [ascoders] Re: Namensräume
- [ascoders] Re: Namensräume
- From: Ralf Siegel
- [ascoders] Re: Namensräume
- From: Andreas Hucks