The Wayback Machine - https://web.archive.org/web/20111102014856/http://www.webreference.com/programming/javascript/rg34/index.html

WebReference.com logo
tip archive  •   about  •   sitemap  •   contact  •   jobs  •   write for us  •   subscribe

Newletters


[next]

Debugging JavaScript: Beyond Alerts

By

Social Bookmark

C/C++ Developer (NYC)
Next Step Systems
US-NY-New York

Justtechjobs.com Post A Job | Post A Resume


There was a time when debugging JavaScript required a liberal sprinkling of alert messages. Sometimes, just figuring out which line caused the error was an ordeal. Not so anymore. As JavaScript became more and more object oriented and grew in scope, a simple alert box no longer sufficed. Ajax, in particular, created a major impediment to debugging scripts, as its asynchronous nature introduced a multi-threading aspect to the language. One try at debugging a chat application that uses periodic polling will attest to that fact! As part of multi-tiered applications, scripts can be written, debugged, and even tested using frameworks' built-in functionality or by specialized software. In today's article, we'll begin examining some of the latest ways of debugging your JavaScript code.

The Trouble with Alerts

There are a few reasons that alerts are often inadequate for debugging purposes:

Tracing Script Execution

In application development, tracing is a specialized use of event logging to record information about a program's execution. Whereas event logging can be used by system administrators or technical support personnel to diagnose common problems with software, tracing is more commonly confined to programmers for debugging or diagnostic purposes.

To better display object and class attributes, industrious developers have taken the time to write some useful tracing functions. One such instance was written by Eric Wendelin and later expanded by Luke Smith. Here is the result of their labors, as presented at ajaxian.com:

To use the code to your page, be sure to change the YOUR_NAMESPACE to your app's namespace or remove it if you don't have one and you're certain that there is no preexisting getStrackTrace() function - and that includes within any libraries that are utilized by your page. If you're not sure, you can always try calling the function before adding the code and confirm that the browser does not recognize it.

I have tried my own hand at writing debugging utilities. I borrowed liberally from functions that are included with the Prototype and Mootools frameworks. The functions are predicated on the fact that JavaScript, like Java, also provides some degree of Class Reflection. However, some objects, such as Arrays and Functions, require some fairly inventive coding to identify and/or expound:


[next]

Recent Articles

WebReference.com site name
Flashmaps' DynamicLocator: Interactive Maps for Small Areas
Flashmaps' AreaSelector: Interactive Maps for Wide Areas
The DB Mapper: Interactive Street-level Maps of U.S. and Canada
internet.com site name
Top 10 SQL Server Counters for Monitoring SQL Server Performance
4 Eclectic Web Tools for Small Business
2011 Holiday Shopping Research and Trends


Internet.com
The Network for Technology Professionals

About Internet.com

Legal Notices, Licensing, Permissions, Privacy Policy.
Advertise | Newsletters | E-mail Offers