GeeCON Prague 2014*
The moose likes HTML, CSS and JavaScript and the fly likes Standalone JavaScript programs Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "Standalone JavaScript programs" Watch "Standalone JavaScript programs" New topic
Author

Standalone JavaScript programs

Hussein Baghdadi
clojure forum advocate
Bartender

Joined: Nov 08, 2003
Posts: 3479

Hi,
I'm not a JavaScript Ninja so my question may sound really silly.
Is there a way to run JavaScript code outside the browser. I'm looking for something like:
terminal $ jsvm binary-tree.js
Thanks all.
Eric Pascarello
author
Rancher

Joined: Nov 08, 2001
Posts: 15376
    
    6
https://developer.mozilla.org/en/introduction_to_the_javascript_shell
Karthik Shiraly
Ranch Hand

Joined: Apr 04, 2009
Posts: 513
    
    6
Another solution is using JRE6 Scripting API (javax.script.*). This is suitable if the JS code does not involve changing its container - for example, you can't use this to reliably run JS code that manipulates browser DOM.
It's good for testing data structures, or following DRY principles (example: parameter validation rules can be coded just once in JS and invoked from both client side and server side).

Example:

Hussein Baghdadi
clojure forum advocate
Bartender

Joined: Nov 08, 2003
Posts: 3479

Thank you Karthik but actually Eric's link is what I'm looking for. Thank you guys.
 
GeeCON Prague 2014
 
subject: Standalone JavaScript programs