Here’s an interactive shell for use within emacs that allows the user to run and execute Javascript. There are a few interactive shells around, built on spidermonkey or Rhino, but this one works on Windows and the built-in Windows Script Host (Cscript.exe) that can run Javascript. It also depends on the Javascript REPL from KobyK. In fact, this elisp code is just an integration of kobyk’s work into emacs.
The primary benefit of an interactive Javascript is that developers can run and test Javascript code that is not browser-centric in an interactive shell, without leaving emacs. It’s good for testing, iterative development.
Using this code, it’s possible, from within the editing buffer of a .js file, to send the region to the shell to be evaluated. It’s also possible to send complete files to the Javascript shell. This allows, for example the developer to mark a large function, then send it to the shell, then pop to the shell and immediately invoke that function interactively, to see the results. After changing the function in the regular editing buffer, you can send it again to the shell, and test again. Much faster than loading up a browser.
Also the shell does simple completion on properties of Javascript objects. type: obj.TAB and you get a completion list.
This was inspired by the JS-comint mode on sourceforge.
The shell does not, in itself, provide a mock DOM, and so is unsuitable, by itself, for running tests of browser-centric code. You couldn’t run jQuery in it, for example.
This module does have the ability to load in separate modules when you begin the shell. For example, you can load in json2.js, into the shell, or a module with extensions to the string prototype. You can see that in the screenshot above.
Theoretically, if you had a suitable mock of a DOM implemented in JavaScript, you could load it into this shell to enable testing of browser-centric code.
For other shells or Javascript REPLs, including those that are multi-platform, see the CategoryJavaScript page.