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

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

(11), line 7, local variable information…<br />

c(10), line 11, local variable information…<br />

When a() returns, b() will continue executing on line 8, and when it returns, c() will continue<br />

executing on line 12.<br />

A listing of the call stack is known as a stack trace, and can be useful when debugging. Mozilla<br />

provides the stack property of the Error object (discussed in detail in a following section) for<br />

just such occasions. We can augment our previous example to output a stack trace in Mozilla:<br />

function a(x)<br />

{<br />

}<br />

document.writeln(x);<br />

document.writeln("\n----Stack trace below----\n");<br />

document.writeln((new Error).stack);<br />

function b(x) {<br />

}<br />

a(x+1);<br />

function c(x) {<br />

}<br />

b(x+1);<br />

c(10);<br />

<strong>The</strong> output is shown in Figure 23-4. <strong>The</strong> top of the trace shows that the Error() constructor is<br />

called. <strong>The</strong> next line indicates that the function that called the error constructor is a() and its<br />

argument was 10. <strong>The</strong> other data on the line indicates the filename where this function is<br />

defined (after the @) as well as the line number (after the colon) the interpreter is currently<br />

executing. Successive lines show the calling functions as we‘d expect, and the final line shows<br />

that c() was called on line 16 of the currently executing file (the call to c() isn‘t within any<br />

function, so the record on the stack doesn‘t list a function name).

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

Saved successfully!

Ooh no, something went wrong!