views:

180

answers:

3

Is there any way to get the definition (public methods and properties) of an object in Javascript that is unknown?

In reality, I know what the object should be, but it's having problems accessing Methods that should be there, so I want to see what Methods are defined.

I have no control over this object so I can't use JSON or toString. Any other ideas?

A: 

If you already expecting a known type of object, but still rather would like to check either particular method exists, you could do this with:

if ("method" in object) ....
Laimoncijus
for debugging you could also use Firebug extension on Firefox, there you can simply dump an object and see what methods/properties it has...
Laimoncijus
Debugging is what I'm trying to do. However this object is an ActiveX object that only works in IE...so is there an equivalent action in IE's Web Developer Tools?
Pselus
there is also Firebug Lite, 100% JavaScript solution, but for this you need to be able to include somehow JS file. See their page for more details:http://getfirebug.com/firebuglite
Laimoncijus
+2  A: 

Check out "Javascript: The Good Parts", page 23 on reflection.

Some notes: use for(key in o) to enumerate the members of o. This will include members inherited via the prototype chain.

You can use o.hasOwnProperty(name) to determine if something is a direct member of an object, or included via the protoype chain.

You can use typeof() to distinguish functions from properties.

Frank Schwieterman
A: 

If you have VS 2005 have a look at Debugging client JavaScript in VS 2005

Gaby