Object.prototype.inspect ?

Tobie Langel tobie.langel at gmail.com
Thu Mar 12 12:27:51 PDT 2009

On Mar 12, 2009, at 19:57 , P T Withington wrote:

> As long as there is a standard way to enumerate the properties of an  
> Object and a standard way to determine an Object's 'class' (i.e.,  
> constructor, which you can only do in ES3 if you annotate each  
> object yourself), you can write your own inspect and this is a dandy  
> place to allow innovation, IMO.

Well, it doesn't seem like the later is standardized either. There is:

function getClass(obj) {
   return (Object.prototype.toString.call(obj) || '').slice(8, -1);

for built-in objects (and host objects in some implementations).  
Possibly something like this for custom objects (pending specification  
of Function.prototype.name) or, in the meantime, function  
decompilation (also unspecified and with issues of its own):

getConstructorName(obj) {
   return obj.constructor.name;

> There is a big difference between being able to inspect/debug an  
> object for human legibility and expecting that you can convert an  
> object to a source expression that when evaluated will be "equal" to  
> the original object (for some definition of equal!).

Agreed. My request was - and still is - for the former.

More information about the Es-discuss mailing list