Sneaky Abstractions

Subscribe to my Feed, follow me on , recommend me on Working With Rails or see my code on GitHub

IRB for JavaScript

Posted on May 09, 2007 10:47 Tagged with irb, javascript, spidermonkey.

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.

Super Disco Breakin