toJSONString and other introspections

Lars T Hansen lth at acm.org
Mon Jul 30 04:06:59 PDT 2007


On 6/25/07, Kris Zyp <kriszyp at xucia.com> wrote:
> I was wondering how toJSONString should handle objects with members of
> multiple namespaces?
> For example:
> namespace N1
> obj = {};
> obj.public::a=1
> obj.N1::b=2
> obj.toJSONString() -> ?
> Would toJSONString simply not be able to serialize in such a way that the
> object can deserialized?

The agreement is that default JSON serialization will discard the
namespace (in the same way it currently discards eg function objects).

> The reference implementation does not seem to have
> toJSONString implemented yet.

Real Soon Now.

> Also, Is there specific way that toJSONString should behave when called for
> a class? Will it just perform a normal enumeration (i.e. not override the
> default toJSONString)?

That depends on the class.  The dictionary class (Map, HashMap, Dict,
Dictionary, Hashtable, HashTable) will probably want toJSONString to
capture its key-value pairs, probably, at least when those keys are
strings.  But it is my understanding that a user-authored class
deriving from Object would get Object's "toJSONString" by default, and
that function would perform some form of standard enumeration.

> Also, is there a way to determine what the class object is for a given
> object?

At present, the meta-objects proposal (see
http://developer.mozilla.org/es4/proposals/meta_objects.html for an
older version) allows a Type object to be extracted from any value,
but does not specify whether those objects are the same as the
classes.

The type system is currently evolving, this proposal may change some.

> In the reference implementation, the toString() will tell you name
> of the class, but is there a way to access to the class object (like
> getClass() in Java) from an instance object?
>
> Also, should there be any
> introspection available on a
> class object (beside the static members), such as the determining member
> attributes?

See the same proposal.

--lars



More information about the Es4-discuss mailing list