473,405 Members | 2,282 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

How to determine an object's class and properties?

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

Jul 23 '05 #1
1 8810
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[i]+'\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>

Jul 23 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

18
by: Christopher W. Douglas | last post by:
I am writing a VB.NET application in Visual Studio 2003. I have written a method that handles several events, such as closing a form and changing the visible status of a form. I have some code...
16
by: sneill | last post by:
How is it possible to take the value of a variable (in this case, MODE_CREATE, MODE_UPDATE, etc) and use that as an object property name? In the following example I want 'oIcon' object to have...
2
by: dsandor | last post by:
I have a class that is inherited by another class. Let say: public class vehicle { public string color { get ... set ... } }
3
by: mnet123 | last post by:
I am using "Server.Transfer()" to send data to an ASP.NET page that's sole purpose is to display messages. I am using "Server.Transfer since I can set the contents of the message I want to display...
2
by: jmhmaine | last post by:
I've created a lookup class for a windows form application and I'm stuck on how on using the collection object. The process is simple, if the item is in the collection then return that object, if...
11
by: Kevin Prichard | last post by:
Hi all, I've recently been following the object-oriented techiques discussed here and have been testing them for use in a web application. There is problem that I'd like to discuss with you...
4
by: ABC | last post by:
I want to check the form's controls have or not the specific properties or events. How to determine or gather the properties list under the run-time environment?
3
by: Simon Hart | last post by:
Hi, I am trying to implement some functionality as seen in MS CRM 3.0 whereby a basic Xml is deserialized into an object which contains properties. What I want to do from here is; cast the basic...
4
by: =?Utf-8?B?R3JlZw==?= | last post by:
I am a newbie to WCF so please forgive if this is an obvious question. I have the following. (Service contract) IEmployee public interface IEmployee { List<EmployeeGetEmployeeByID(string...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.