You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
If you haven't installed js2 of some form, go here.
Now that you have it installed, lets get a "hello world" working. I'm going to use the command js2 to represent the flavor of js2 you have installed (js2-node, js2-ruby)
Create and input and output directory:
mkdir src lib
Create a file called Hello.js2 in your input directory (src/Hello.js2) and paste this in:
class Hello {
function world() {
return "world";
}
}
var hello = new Hello();
console.log(hello.world()); // for ringo, use "system.print(hello.world())" instead.
Now run:
js2 compile src lib
Alternatively, you can setup a config file so that you don't have to specify the directories every time you want to run js2. To do so, create a js2.json file in the root or ./config directory of your project. Here is a sample js2.json file:
{ "src-dir": "./src", "target-dir": "./lib" }
Depending on your installation you can execute the compiled javascript from the command line:
node lib/Hello.js
ringo lib/Hello.js
js2-ruby run lib/Hello.js
You can also set js2 to "watch" mode where it will periodically check for changed files and compile them for you:
js2 watch src lib
See here for more instructions on how to run js2 on the command line.
Here are more specifics on the various flavors or js2: