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.

Figure 23-4: Using Error.stack to get a stack trace in Mozilla<br />

Other browsers don‘t provide an easy mechanism to get a stack trace, but given the Function<br />

properties discussed in Chapter 5, we can construct what it must look like ourselves.<br />

// Helper function to parse out the name from the text of the function<br />

function getFunctionName(f)<br />

{<br />

}<br />

if (/function (\w+)/.test(String(f)))<br />

else<br />

return RegExp.$1;<br />

return "";<br />

// Manually piece together a stack trace using the caller property<br />

function constructStackTrace(f)<br />

{<br />

if (!f)<br />

return "";<br />

var thisRecord = getFunctionName(f) + "(";

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

Saved successfully!

Ooh no, something went wrong!