Using Function.toString to Troubleshoot JavaScript Issues

By  on  

Sometimes JavaScript bugs can be the most frustrating damn things in the world. That problem is compounded when a JavaScript file is created from multiple files on the server side or you simply aren't familiar with some of the code used in a project (i.e. troubleshooting an issue with a JavaScript framework you aren't familiar with. Sometimes just identifying the code within a function is enough to point you in the correct direction. So to quickly check the code for a given function, I'll type into the console something like:

myProblemFunction.toString();

That would return something like:

function myProblemFunction() {
	/* bunch of code here */
	
	some.problem().code;
	
	/* bunch of code here */
}

Awesome. Now that I can get the function code at a glance, I can more easily browse through what could be causing the issue and see what needs to be changed. Usually any hint you can get toward finding where the issue resides is a big help!

Recent Features

  • By
    9 Mind-Blowing WebGL Demos

    As much as developers now loathe Flash, we're still playing a bit of catch up to natively duplicate the animation capabilities that Adobe's old technology provided us.  Of course we have canvas, an awesome technology, one which I highlighted 9 mind-blowing demos.  Another technology available...

  • By
    5 Awesome New Mozilla Technologies You’ve Never Heard Of

    My trip to Mozilla Summit 2013 was incredible.  I've spent so much time focusing on my project that I had lost sight of all of the great work Mozillians were putting out.  MozSummit provided the perfect reminder of how brilliant my colleagues are and how much...

Incredible Demos

  • By
    CSS Custom Cursors

    Remember the Web 1.0 days where you had to customize your site in every way possible?  You abused the scrollbars in Internet Explorer, of course, but the most popular external service I can remember was CometCursor.  CometCursor let you create and use loads of custom cursors for...

  • By
    HTML5 Context Menus

    One of the hidden gems within the HTML5 spec is context menus. The HTML5 context menu spec allows developers to create custom context menus for given blocks within simple menu and menuitem elements. The menu information lives right within the page so...

Discussion

    Wrap your code in <pre class="{language}"></pre> tags, link to a GitHub gist, JSFiddle fiddle, or CodePen pen to embed!