Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Standalone JavaScript programs

 
Hussein Baghdadi
clojure forum advocate
Bartender
Posts: 3479
Clojure Mac Objective C
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 15385
6
 
Karthik Shiraly
Bartender
Posts: 1208
25
Android C++ Java Linux PHP Python
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 3479
Clojure Mac Objective C
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you Karthik but actually Eric's link is what I'm looking for. Thank you guys.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic