開発
Useful tool for Javascript debugging
denvazh
Recently, I found myself into Javascript programming and very-very soon I bumped into some issues, when I wanted to debug script without running it in some Web-browser.
If you are happy user of OS X(such as myself), it is very easy to do.
Mac OS X already comes with Webkit framework which has a nice tool named JSC.
JSC is a command-line utility that allows to run JavaScript programs outside of the context of a web browser [ ref.].
By default it can be found at:
"/System/Library/Frameworks/JavaScriptCore.framework/Versions/A/Resources/jsc"
To be able to use it as any other command-line tool, let’s create symlink ( so that we don’t have to always use same long path again ).
Open Terminal and run command below:
$: ln -s /System/Library/Frameworks/JavaScriptCore.framework/Versions/A/Resources/jsc /usr/local/bin/jsc
Now you can try some javascript right away:
$: jsc >
NOTE: to be able to get output to STDOUT one has to use debug() instead of conventional console.log().
Let’s try it!
$: jsc > var today = new Date(); undefined > debug(today.toUTCString()); --> Tue, 18 Sep 2012 01:54:29 GMT undefined > debug(today); --> Tue Sep 18 2012 10:54:29 GMT+0900 (JST) undefined
Now we know time difference between JST and UTC :).
Sometimes small hack saves a lot of time when it comes to debugging web-based applications.
Total overkill would be to combine it with nice bisect functionality provided by git.