Sunday, February 12, 2012

Use JavaScript in command line

Get from this link, there is a executable "jsc" in /System/Library/Frameworks/JavaScriptCore.framework/Versions/Current/Resources/. However, which is not in your path by default, so you need to create a link in your /bin:

sudo ln /System/Library/Frameworks/JavaScriptCore.framework/Versions/Current/Resources/jsc /bin/jsc

Then you can just type "jsc" in any command line to execute javascript statements. You can use "quit();" to exit.

ddh$ jsc
> [] + []

> [] + {}
[object Object]
> {} + []
0
> {} + {}
NaN
> quit();
ddh$