Debugging objects in Javascript with prototype.js
Jan.21, 2008 in
Tech
Often when coding complex javascript you’ll wish you had the ability to debug objects or arrays that you are working on – much like Data::Dumper in Perl or var_dump in php (see previous posts on these topics). Prototype.js provides an easy way to do this using the .inspect() method for hashes and arrays:
var myComplexHash = {Element: value, AnotherElement: value2 ... };
alert($H(myComplexHash).inspect());
The $H(myhash).inspect() function returns a debug-oriented string which can be easily deciphered:
<#Hash:{Element: 'value', AnotherElement: 'value2', ... >
Tags: debugging, javascript

Leave a Reply