Skip to main content

Notice: This Wiki is now read only and edits are no longer possible. Please see: https://gitlab.eclipse.org/eclipsefdn/helpdesk/-/wikis/Wiki-shutdown-plan for the plan.

Jump to: navigation, search

Difference between revisions of "VJET/JavaScript Run As"

Line 73: Line 73:
 
VJET launcher automatically loads any js files included using vjo.needs
 
VJET launcher automatically loads any js files included using vjo.needs
  
=== vjojs with dependencies ===
+
=== using simple js with vjojs class ===
  
 +
MyProject/src/foo/MyClass.js
 
<source lang=javascript >
 
<source lang=javascript >
function foo(a){
+
vjo.ctype('foo.MyClass') //< public
alert(a)
+
.protos({
}
+
//>public void foo(Number)
 +
foo : function(a){
 +
vjo.sysout.println(a)
 +
}
 +
})
 +
.endType();
 +
</source>
  
foo(20);
+
MyProject/src/foo/usingbar.js
foo(30);
+
<source lang=javascript >
 +
vjo.needs("foo.MyClass")
 +
foo.MyClass().foo(20);
 +
foo.MyClass().foo(30);
 
</source>
 
</source>
  
should open web browser and display two alert boxes
+
yields
 +
 
 +
<source lang=text>
 +
20.0
 +
30.0
 +
</source>
  
- alert box with 20 in it
 
- alert box with 30 in it
 
  
 
Tested with Indigo SR2 and Juno SR1 versions of Eclipse.
 
Tested with Indigo SR2 and Juno SR1 versions of Eclipse.

Revision as of 15:20, 30 January 2013

VJET supports running JavaScript and vjojs

Simple JS Run with Rhino

Basic run as vjet js application should work for simple functions and vjojs.

VJET provides a simple api for outputting to the console and is automatically wired into Rhino. vjo.sysout and vjo.syserr. This idea was borrowed from java System class.

add this file foo.js into vjet project

function foo(a){
	vjo.sysout.println(a)
}
 
foo(20);
foo(30);


run as vjet js application

yields in eclipse console

20.0
30.0

Simple JS Run with Web Browser

function foo(a){
	alert(a)
}
 
foo(20);
foo(30);

should open web browser and display two alert boxes

- alert box with 20 in it - alert box with 30 in it


js file with vjo.needs dependencies

MyProject/src/foo/bar.js

function foo(a){
	vjo.sysout.println(a)
}

MyProject/src/foo/usingbar.js

vjo.needs("foo.bar")
foo(20);
foo(30);

run as vjet application

yields

20.0
30.0

VJET launcher automatically loads any js files included using vjo.needs

using simple js with vjojs class

MyProject/src/foo/MyClass.js

vjo.ctype('foo.MyClass') //< public
.protos({
	//>public void foo(Number) 
	foo : function(a){
		vjo.sysout.println(a)
	}
})
.endType();

MyProject/src/foo/usingbar.js

vjo.needs("foo.MyClass")
foo.MyClass().foo(20);
foo.MyClass().foo(30);

yields

20.0
30.0


Tested with Indigo SR2 and Juno SR1 versions of Eclipse.

Back to the top