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


[next]

Debugging JavaScript: Beyond Alerts

By

Social Bookmark

Business Systems Analyst - Clearing - SQL Server - ASP - VB (IL)
Next Step Systems
US-IL-Chicago

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
Search Engine Optimization: Selecting and Embedding Keywords
Are Google's Language Translation Web Services Ready for Prime Time?
Installing and Using Meeplace, the Business Review CMS
internet.com site name
IBM DB2 10 for z/OS: Justifying the Upgrade
Living La Vida Colo: Choosing the Right Colocation Facility
FTC Concerns over Social Media Privacy Linger



The Network for Technology Professionals

Search:

About Internet.com

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