Subscribe to my Feed, follow me on Twitter, recommend me on Working With Rails or see my code on GitHub
IRB for JavaScript
Have you ever wished there was a console application for JavaScript, like IRB for Ruby, where you can try things out? Well, there is one and it is part of Mozilla’s SpiderMonkey JavaScript implementation (in C). If you’re on Ubuntu (and maybe Debian too?), installing it is as easy as
apt-get install spidermonkey-bin
Then, run js:
js> Foo = function(){}
function () {
}
js> Foo.prototype.bar = function(){ print('BAR!') }
function () {
print("BAR!");
}
js> foo = new Foo()
[object Object]
js> foo.bar()
BAR!
This may be something that everyone else but me knew about, but I’m pretty excited to have somewhere other than a browser to try out things as I start learning JavaScript properly.

Comments
Atom feed
By John Nunemaker at Fri 14 Mar 21:19
You can also use firebug with firefox. It has a console for testing js stuff.
By Phil at Fri 14 Mar 21:19
Sweet; this is the missing link for stuff that MozRepl is overkill for. Sometimes you just don’t need the chrome overhead.
http://dev.hyperstruct.net/mozlab/wiki/MozRepl
By kangax at Thu 27 Mar 18:14
Nice. I wonder if there are any wrappers for spidermonkey to work with applescript/ruby/etc.
Leave a comment