How to determine an object's class and properties?

L

laredotornado

Hello,
I am working with another's code and when I do

alert(mysteryVar);

I get "[object Object]". I would like to find out the class name,
properties and methods of this mystery variable. How do I do this?

Thanks, - Dave
 
V

VK

Take a copy of my old samurai sword :)
It's 6 years old, used during the Great Browser War to catch
method/properties glitches in NN/IE.
But it's rather simple to adjust it for all your needs - except the
class name, here you need to use myObject.prototype check.

<html>
<head>
<title>props</title>
<meta http-equiv="Content-Type" content="text/html;
charset=iso-8859-1">
<script>
function testObject() {
//var obj = null;
//var obj = Boolean(true); // a primitive value wrapper
var obj = window // an object
//var obj = testObject; // a function pointer

var out = document.forms[0].out; out.value = '';
var who = (obj != null)? typeof(obj) : 'null';
switch(who) {
case 'object':
var arr = new Array();
var prp = null;
for (prp in obj) {arr.push(''+prp+' = '+obj[prp]);}
arr.sort();
for (i=0;i<arr.length;i++) {out.value+=arr+'\n';}
break;
case 'function':
out.value = obj.arguments.callee;
break;
case 'undefined':
out.value = 'undefined';
break;
case 'null':
out.value = 'null';
break;
default:
out.value = who.toUpperCase()+ ' ' + obj.toString();
}
}
</script>
</head>

<body bgcolor="#FFFFFF">
<form>
<input type="button" value="Explore" onclick="testObject()">
<br>
<textarea name="out" cols="64" rows="32"></textarea>
</form>
</body>
</html>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top