[Laszlo-dev] Constructing objects from their string name
P T Withington
ptw at laszlosystems.com
Mon Apr 28 17:02:15 PDT 2008
The correct fix is to fix getChildClass, which currently says:
<method name="getChildClass">
if (this.isleaf) return null;
return this.constructor.classname;
</method>
I guess the confusion is that it implies it returns a class, but it is
actually returning a class _name_ (a string).
There are two choices of how to fix it. If you need a tag name,
because you are going to look it up in the `lz` module (as is done in
say, baselist#addItem) you want:
this.constructor.tagname
If you look this up in lz:
lz[this.constructor.tagname]
you will get the constructor for the class that implements that tag.
But, if you just want the constructor directly, just say:
this.constructor
It should always be the case that:
lz[this.constructor.tagname] === this.constuctor
There's a bunch of confusion that has been introduced because we have
made classnames non-global, and they don't necessarily match the name
of the tag they implement. (They never did for the LFC, we are now
just uniform for all classes that implement tags).
I guess the confusion is increased because to the LZX programmer, when
they say:
<class name="foo" ...
they think they have created a class named `foo`, but really they have
created a (Javascript) class with an anonymous name that implements
the tag named `foo`. The mapping from tag name to implementation
class is through the `lz` table. Perhaps we should rename the
Javascript `classname` property to `implementationclassname` or
perhaps get rid of it altogether, as it seems to only be a source of
confusion... I'll leave it to you if you want to file an improvement
request to that effect.
---
In any case, please grep around the components in case `classname` is
being mis-used elsewhere in the components. Thanks!
On 2008-04-28, at 19:42 EDT, Philip Romanik wrote:
> Hi Tucker,
>
> There is a bug in the tree object caused by code in basetree.lzx:
>
> var c = this.getChildClass();
> if (c != null) {
> new c(this, args, null, true);
> }
>
> The dhtml error is TypeError: c is not a constructor.
>
> The code is trying to construct an object given the string name of
> the class, ie:
>
> new lz.tree.classname
>
> Is the correct fix to do the equivalent of:
> new ConstructorMap[lz.tree.tagname]
>
More information about the Laszlo-dev
mailing list