JavaScript Command Line Shell OS X

So…

I was writing a whole bunch of JavaScript recently and was getting incredibly tired of having to refresh the browser to see if things were working.

Yes, I have FireBug and such but what I really want is a command-line JavaScript interpreter like my iPython.

To make a long story short, none of the instructions I found for building SpiderMonkey worked on OS X and I couldn’t find a binary so I went to plan B: Rhino.

Download and unzip. What you’ll get is a directory named `rhino1_7R2`.

So, once you have that, just go get jLine. It’s a single .jar file, stick that into your `rhino1_7R2` directory. Mine is named `jline-0_9_5.jar`.

Make sure you’re in your `rhino1_7R2` directory where you should see something like this if you do an `ls`:

(~/rhino1_7R2)# ls *.jar
-rw-r--r--@ 1 ssteiner  staff    46424 Dec  6 09:00 jline-0_9_5.jar
-rw-r--r--  1 ssteiner  staff  1164702 Mar 22  2009 js-14.jar
-rw-r--r--  1 ssteiner  staff   871260 Mar 22  2009 js.jar

then type the oh-so-completely-obvious command:

(~/rhino1_7R2)# java -classpath js.jar:jline-0_9_5.jar jline.ConsoleRunner
 org.mozilla.javascript.tools.shell.Main

You’ll see the `js>` prompt and there you are; a full JavaScript command line to try things out in.

I got some great help from this article when I was first starting this exploration and he goes into mixing Java and JavaScript code a little bit which is of no interest to me, at this point.

Sure is nice to have a command line to whack around to try out regular expressions and such though…