11.12.2012 Views

JavaScript 2.0-The Complete Reference, Second ... - freecodingtutorial

JavaScript 2.0-The Complete Reference, Second ... - freecodingtutorial

JavaScript 2.0-The Complete Reference, Second ... - freecodingtutorial

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Once a script has been loaded into a debugger, it can be run one line at a time or instructed to<br />

halt at certain breakpoints. <strong>The</strong> idea is that once execution is halted, the programmer can<br />

examine the state of the script and its variables in order to determine if something is amiss. You<br />

can also watch variables for changes in their values. When a variable is watched, the debugger<br />

will suspend execution whenever the value of the variable changes. This is tremendously useful<br />

in trying to track down variables that are mysteriously getting clobbered. Most debuggers also<br />

allow you to examine stack traces, the call tree representing the flow of execution through<br />

various pieces of code that we saw in the previous section. And to top it all off, debuggers are<br />

often programmed to alert the programmer when a potentially problematic piece of code is<br />

encountered. And because debuggers are specifically designed to track down problems, the<br />

error messages and warnings they display tend to be more helpful than those of the browser.<br />

<strong>The</strong>re are several major <strong>JavaScript</strong> debuggers in current use. By far the most popular free<br />

debugger is Venkman, the debugger of the Mozilla project. It integrates with Mozilla and<br />

Netscape 6+ and offers all the features most developers might need, including a profiler<br />

enabling you to measure the performance of your code. If you‘ve installed the ―Full‖ version of a<br />

Mozilla-based browser, this debugger is already available to you. If not, use a Mozilla-based<br />

browser to access http://www.mozilla.org/projects/venkman/ and follow the installation<br />

instructions. This should be as simple as clicking on the .xpi file for the version you want. To<br />

start the debugger, select Tools | Web Development | <strong>JavaScript</strong> Debugger. Figure 23-6 shows<br />

a screenshot of Venkman.<br />

Figure 23-6: <strong>The</strong> Venkman <strong>JavaScript</strong> debugger in action<br />

A somewhat popular free utility for Internet Explorer 4 and later is the Microsoft Script<br />

Debugger. It is available from http://msdn.microsoft.com/scripting and integrates with<br />

Internet Explorer if installed. To enable this integration, select Tools | Internet Options. In the<br />

Advanced tab, uncheck Disable Script Debugging, as shown in Figure 23-7. Whenever<br />

debugging is turned on in IE and you load a page that has errors, the dialog in Figure 23-7 is<br />

shown in place of the normal error message, allowing you to load the page into the debugger.

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!