Object.prototype.inspect ?

P T Withington ptw at pobox.com
Thu Mar 12 14:23:55 PDT 2009


On 2009-03-12, at 17:04EDT, Brendan Eich wrote:

> On Mar 12, 2009, at 1:54 PM, P T Withington wrote:
>
>> But, I would very much like to see a standard way to discover an  
>> Object's constructor, and a way to enumerate _all_ the properties  
>> of an object.  I know there is a tension between security and  
>> introspection.  I don't know if this is something that can be  
>> handled by the presumably already-overloaded strict mode.
>
> ES3.1 has Object.getOwnPropertyNames and  
> Object.getOwnPropertyDescriptor, so you can go to town with those.

Excellent.  I almost guessed correctly, I called it  
objectOwnProperties: http://tinyurl.com/atcasp

> Identifying the constructor is harder. Having to slice a substring  
> out of Object.prototype.toString.call(obj) is disgusting, but it  
> kind of works. Not sure about all the various non-standard class  
> names formatted that way (IE calls DOM classes "Object"?!).

So, why can't we standardize the `constructor` property, that seems to  
exist in some implementations, to actually return the constructor of  
the object (and not the constructor of the object's prototype, which  
is useless)?


More information about the Es-discuss mailing list