Javascript

Is there a third-party add-on / application or some way to reset the map of objects in the script debugger for a JavaScript object?

Here is the situation ... I have a method that is called twice, and each time something else. I'm not sure what else, but there is something. Therefore, if I can reset all the properties of a window (or at least window.document) into a text editor, I could compare the state between two calls with a simple file diff. Thoughts?

+74
javascript
Apr 14 '09 at 20:35
source share
8 answers

Firebug + console.log(myObjectInstance)

+61
Apr 14 '09 at 20:36
source share
— -
 console.log("my object: %o", myObj) 

Otherwise, you will get a string representation sometimes displaying:

 [object Object] 

or some such.

+103
Jan 05 '11 at 19:24
source share
 function mydump(arr,level) { var dumped_text = ""; if(!level) level = 0; var level_padding = ""; for(var j=0;j<level+1;j++) level_padding += " "; if(typeof(arr) == 'object') { for(var item in arr) { var value = arr[item]; if(typeof(value) == 'object') { dumped_text += level_padding + "'" + item + "' ...\n"; dumped_text += mydump(value,level+1); } else { dumped_text += level_padding + "'" + item + "' => \"" + value + "\"\n"; } } } else { dumped_text = "===>"+arr+"<===("+typeof(arr)+")"; } return dumped_text; } 
+41
Jun 10 2018-10-10T00:
source share

If you use Chrome, Firefox, or IE10 +, why not expand the console and use

 (function() { console.dump = function(object) { if (window.JSON && window.JSON.stringify) console.log(JSON.stringify(object)); else console.log(object); }; })(); 

for a concise, cross-browser solution.

+33
Jun 18 '13 at 10:43
source share

Just use:

 console.dir(object); 

You will get a beautiful view of the object with interactive access. Works in Chrome and Firefox.

+18
May 23 '12 at 14:54
source share

For Chrome / Chromium

 console.log(myObj) 

or equivalent

 console.debug(myObj) 
+11
Jul 03 '10 at 11:05
source share

In Chrome, click 3 dots and click "Other Tools" and click "Developer." At the console, enter console.dir (yourObject). Click this link to view an example image.

0
Nov 09 '16 at 13:58
source share

Using console.log(object) , you will throw your object into the Javascript console, but this is not always what you want. Using JSON.stringify(object) returns most of the things that will be stored in the variable, for example, to send it to enter the text area and send the contents back to the server.

0
Nov 27 '17 at 6:17
source share



All Articles