Thursday, November 26, 2009

JavaScript development environment

disclaimer - these postings are quite unfriendly - perhaps I'll edit them into something more readable when they seem to be kind of complete

so I decided to get back onto the JavaScript thing. The purpose of this being to do work for upcoming projects in Max/MSP and some web application stuff (via ajax kind of ways of doing things I imagine).

What it comes down to is re-learning the language (whoops) and the best way to code particular tasks. So I want something 'platform neutral' ie. not to load into a web browser etc just to see if it works...

Mozilla Rhino comes to the rescue: a JS interpreter written in Java - which opens up some nice ideas for embedding, calling Java classes from your script etc. Here, I'm just going to use the JS shell utility as a simple execution shell to call files containing js code. The method of calling it via the command line is a bit tedious, so the following is neaters:

This is the basic setup once the Rhino download is safely unpacked in /opt (& referred to via a link: /opt/rhino.

a) add the rhino jars (js.jar & js-14.jar) to your CLASSPATH.
b) create an alias in your shell:

alias js="java org.mozilla.javascript.tools.shell.Main"
Then you can simply execute a file of JS code with:

> js ./test_file.js

Rhino flags etc should all work etc.

easy. Quick & Dirty.

No comments: