Sunday, June 7, 2009

Scoped Lookup (Now in 3.0.0b1)

This was originally posted to the ZJS News wikipage 31-May-2009, but was moved here instead.

The massive rewrite required of the internals of $namespace, $mixin and $class to support base-class-by-name is done! I was surprised at just how differently things had to be done to defer resolution of class names! The first 80% went quickly: support for classes added to a namespace. The second 80% was worse: support for inner classes.

The code is not much larger than it was without this feature. It's just more interesting.

In the end, the unit test now looks something like this:


A : $class(
{
ctor : function ()
{
$super(arguments).call(this);
}
}),

B : $class("A",
{
ctor : function ()
{
$super(arguments).call(this);
}
}),

C : $class("A",
{
N : $class(
{
Q : $class("N",
{
})
})
}),

D : $class("B",
{
N : $class("E.E2",
{
ctor : function ()
{
$super(arguments).call(this);
},

Q : $class("N",
{
ctor : function ()
{
$super(arguments).call(this);
}
})
})
}),

E : $class("C",
{
E2 : $class("E3",
{
ctor : function ()
{
$super(arguments).call(this);
}
}),

E3 : $class("B",
{
ctor : function ()
{
$super(arguments).call(this);
}
})
})


Remember, this is just to test the mechanism in a worst-case way; don't ever try something like this in a real program! If you do, at least don't say you got the idea from me!

No comments:

Post a Comment