Created
July 2, 2013 14:06
-
-
Save micc83/5909588 to your computer and use it in GitHub Desktop.
Javascript var_dump (for diehard PHP coder)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function varDump( Obj ) { | |
this.eplode = function( theObj ){ | |
var output = ("<ul style='list-style:none;padding-left:20px;margin:0;color:#02adea;'>"); | |
if( typeof theObj == 'object' ){ | |
for( var p in theObj ){ | |
output += "<li style='font-size:12px;'>"; | |
if( theObj[p] && | |
( theObj[p].constructor == Array || theObj[p].constructor == Object ) ){ | |
output += "[" + p + "] => " + theObj[p].constructor.name; | |
output += this.eplode(theObj[p]); | |
} else { | |
output += "[" + p + "] => " + this.escapeme( theObj[p] ); | |
if ( theObj[p] || theObj[p] === false ) | |
output += " (" + theObj[p].constructor.name + ")" ; | |
} | |
output += "</li>"; | |
} | |
} else { | |
output += "<li style='font-size:12px;'>\"" + this.escapeme( theObj ) + "\" (" + theObj.constructor.name + ")</li>"; | |
} | |
output += "</ul>"; | |
return output; | |
} | |
this.escapeme = function( text ) { | |
return escape(text).replace(/%(..)/g,"&#x$1;"); | |
} | |
document.body.innerHTML = '<div class="debug_box" style="font-family: Consolas,monospace;margin:1%;padding:30px 20px 20px 5px;border:5px solid #eee;background:#fafafa;border-radius:10px;position:absolute;bottom:0;left:0;max-width:80%;overflow:auto;max-height:80%"/><span style="font-size:12px;font-weight:800;position:absolute;right:10px;top:10px;color:#eee;">VAR DUMP</span>' + this.eplode( Obj ) + '</div>' + this.document.body.innerHTML; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment