How can I inspect an Object in an alert box? Normally alerting an Object just throws the nodename:
alert(document);
But I want to get the properties and methods of the object in the alert box. How can I achieve this functionality, if possible? Or are there any other suggestions?
Particularly, I am seeking a solution for a production environment where console.log and Firebug are not available.
The
for–inloops for each property in an object or array. You can use this property to get to the value as well as change it.Note: Private properties are not available for inspection, unless you use a “spy”; basically, you override the object and write some code which does a for-in loop inside the object’s context.
For in looks like:
Some sample code:
Edit: Some time ago, I wrote my own inspector, if you’re interested, I’m happy to share.
Edit 2: Well, I wrote one up anyway.