Closed Thread Icon

Preserved Topic: Dump an object properties and methods (Page 1 of 1) Pages that link to <a href="https://ozoneasylum.com/backlink?for=18005" title="Pages that link to Preserved Topic: Dump an object properties and methods (Page 1 of 1)" rel="nofollow" >Preserved Topic: Dump an object properties and methods <span class="small">(Page 1 of 1)</span>\

 
lallous
Paranoid (IV) Inmate

From: Lebanon
Insane since: May 2001

posted posted 05-30-2001 08:54

hello,
anyone knows how can i write a code that can dump whole object's methods and properties?
like for example:

dumpobject(window.document);

and i get whole objects within this last one and whole properties and stuff?

And anyone knows a good and fast JavaScript debugger other than DreamWeaver's one?

Thanks,

-=l=-

bitdamaged
Maniac (V) Mad Scientist

From: 100101010011 <-- right about here
Insane since: Mar 2000

posted posted 05-30-2001 18:48

I'm not sure what you want here.

Do you want tho get a list of the properties/methods?
and their values?





Walking the Earth like Kane

mr.maX
Maniac (V) Mad Scientist

From: Belgrade, Serbia
Insane since: Sep 2000

posted posted 05-30-2001 20:29

This can help you to get started:

<SCRIPT TYPE="text/javascript" LANGUAGE="JavaScript">
<!-- ;
// Written by mr.maX, http://www.max.co.yu/
for (x in document) {
eval("y = document." + x);
document.writeln("document." + x + " = " + y + "<br>");
}
// -->
</SCRIPT>

Slime
Lunatic (VI) Mad Scientist

From: Massachusetts, USA
Insane since: Mar 2000

posted posted 05-30-2001 22:16

Max, max, max. That's an unnecessary use of the eval function.

This is the code I use for that trick, very similar to max's:

var obj = window; // replace window with whatever object you want the properties of.
var msg = "";
for (prop in obj)
{
&nbsp;&nbsp;&nbsp;&nbsp;msg += prop + " = " + obj[prop] + " &#0124; &#0124;

mr.maX
Maniac (V) Mad Scientist

From: Belgrade, Serbia
Insane since: Sep 2000

posted posted 05-30-2001 22:37

Slime, that's a part of a much more complex script (without any evals). I just copied one part and added that eval to make things simple, heh...

linear
Paranoid (IV) Inmate

From: other places
Insane since: Mar 2001

posted posted 05-30-2001 22:47

Yay! super excellent!
Also change

Slime
Lunatic (VI) Mad Scientist

From: Massachusetts, USA
Insane since: Mar 2000

posted posted 05-31-2001 02:29

How about this...

javascript:var obj = window[prompt("What object?")]; var msg = ""; for (prop in obj){ msg += prop + " = " + obj[prop] + "\n";} alert(msg);

linear
Paranoid (IV) Inmate

From: other places
Insane since: Mar 2001

posted posted 05-31-2001 06:23

Hmm, I have some probs with that. Looks like it should work, but I get empty alerts back for most of the objects I want to poke at. Maybe I'm just sloppy with capitalization.

lallous
Paranoid (IV) Inmate

From: Lebanon
Insane since: May 2001

posted posted 05-31-2001 09:15

hi guys!
thanks for your help, now plz help me enhancing it by making it recursive,...i tried but i got stuck!
beware...when you run this code below your browser might crash.

<SCRIPT TYPE="text/javascript" LANGUAGE="JavaScript">
<!-- ;
function padToStr(str, what, times)
{
var t = "";
for (i=0; i < times; i++)
t += what;
return (t + str);
}

function dumpObj(obj, msg, level)
{
for (prop in obj)
{
line = prop + " = " + obj[prop] + "\n";
if (obj[prop] && typeof(obj[prop])=="object")
msg = dumpObj(obj[prop], msg, level+1);
msg = msg + padToStr(line, " ", level);
}
return msg;
}

var msg="";
msg = dumpObj(window, msg, 0);
alert(msg);
</SCRIPT>


[edit] why idents are removed when i post?

[This message has been edited by lallous (edited 05-31-2001).]

Slime
Lunatic (VI) Mad Scientist

From: Massachusetts, USA
Insane since: Mar 2000

posted posted 05-31-2001 18:06

indents are collapsed because HTML renders all whitespace as a single space, heh. =) use &amp;nbsp; for a space if necessary, or use the [ code ] [ /code ] tags (w/o spaces) if you like.

mr.maX
Maniac (V) Mad Scientist

From: Belgrade, Serbia
Insane since: Sep 2000

posted posted 05-31-2001 21:56

Don't use CODE UBB tag, it will mess up copy/paste (everything will be on one line and you'll have to go to edit message page in order to see code right)...



[This message has been edited by mr.maX (edited 05-31-2001).]

« BackwardsOnwards »

Show Forum Drop Down Menu