-
Notifications
You must be signed in to change notification settings - Fork 3
/
objprint.js
77 lines (69 loc) · 2.1 KB
/
objprint.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
//----------------------------------------------------------------------------
// Object Printer Function (for debug)
function objprint(a,name)
{
document.write("<table border='1' bgcolor='#EEEEEE' border='1' cellpadding='2' cellspacing='0' bordercolorlight='#000000'>");
_objprint(a,name);
document.write("</table>");
};
function _objprint(obj,name)
{
if(typeof obj == "object") // all objects in here
{
if (obj && obj.constructor) // detect specific objects for special handling here
{
if (obj.constructor == Array) _parray(obj,name);
else if (obj.constructor == String) _pstring(obj,name);
else _pgeneric(obj,name);
}
else _pgeneric(obj,name);
}
else _pbase(obj,name);
}
function _parray(a,name) // array object
{
if (a.length==0) _pempty("array",name)
for(var i=0; i < a.length; i++)
_objprint(a[i],name+"["+i+"]");
};
function _pstring(obj,prefix) // string object
{
document.write("<tr><td>",prefix,"</td><td>\"",obj,"\" (String object)</td></tr>");
}
function _pgeneric(obj, name) // generic object
{
if (!_listprops(obj,name)) _pempty("object",name);
};
function _pempty(type,prefix) // object with no properties
{
document.write("<tr><td>",prefix,"</td><td>[empty "+type+"]</td></tr>");
};
function _pbase(obj,prefix) // base type
{
document.write("<tr><td>",prefix,"</td><td>",obj," (",typeof obj,")</td></tr>");
_listprops(obj,prefix);
};
function _listprops(obj,name)
{
var hasprops = false;
for (var i in obj)
{
hasprops = true;
_objprint(obj[i],name+"."+i);
}
return hasprops;
/*
var _extraprops = ["prototype","__proto__"];
if (typeof obj != "undefined")
for (var i=0; i < _extraprops.length; i++)
if (typeof obj[_extraprops[i]] != "undefined")
{
hasprops = true;
//_objprint(obj[_extraprops[i]],name+"."+_extraprops[i]);
document.write("<tr><td>",name,".",_extraprops[i],"</td><td>",obj[_extraprops[i]],"(",typeof obj[_extraprops[i]],")</td></tr>");
}
{
hasprops = true;
document.write("<tr><td>",name,".constructor</td><td>",obj.constructor," (",typeof obj.constructor,")</td></tr>");
} */
};