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 1: Line 1:
 +
== VJET supports running JavaScript and vjojs  ==
  
 +
=== Simple JS Run with Rhino  ===
  
== VJET supports running JavaScript and vjojs ==
+
Basic run as vjet js application should work for simple functions and vjojs.
  
=== Simple JS Run with Rhino ===
+
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.
  
Basic run as vjet js application should work for simple functions and vjojs.
+
add this file foo.js into vjet project
  
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.
+
<source lang="javascript">
 
+
add this file foo.js into vjet project
+
 
+
<source lang=javascript>
+
 
function foo(a){
 
function foo(a){
 
vjo.sysout.println(a)
 
vjo.sysout.println(a)
Line 18: Line 16:
 
foo(20);
 
foo(20);
 
foo(30);
 
foo(30);
</source>
+
</source>  
 
+
  
run as vjet js application  
+
<br> run as vjet js application  
  
yields in eclipse console
+
yields in eclipse console  
  
<source lang=text>
+
<source lang="text">
 
20.0
 
20.0
 
30.0
 
30.0
</source>
+
</source>  
  
=== Simple JS Run with Web Browser ===
+
=== Simple JS Run with Web Browser ===
  
<source lang=javascript >
+
<source lang="javascript">
 
function foo(a){
 
function foo(a){
 
alert(a)
 
alert(a)
Line 39: Line 36:
 
foo(20);
 
foo(20);
 
foo(30);
 
foo(30);
</source>
+
</source>  
  
should open web browser and display two alert boxes
+
should open web browser and display two alert boxes  
  
- alert box with 20 in it
+
- alert box with 20 in it - alert box with 30 in it  
- alert box with 30 in it
+
  
=== js file with vjo.needs dependencies ===
+
=== js file with vjo.needs dependencies ===
  
MyProject/src/foo/bar.js
+
MyProject/src/foo/bar.js <source lang="javascript">
<source lang=javascript >
+
 
function foo(a){
 
function foo(a){
 
vjo.sysout.println(a)
 
vjo.sysout.println(a)
 
}
 
}
</source>
+
</source>  
  
MyProject/src/foo/usingbar.js
+
MyProject/src/foo/usingbar.js <source lang="javascript">
<source lang=javascript >
+
 
vjo.needs("foo.bar")
 
vjo.needs("foo.bar")
 
foo(20);
 
foo(20);
 
foo(30);
 
foo(30);
</source>
+
</source>  
  
run as vjet application yields
+
run as vjet application yields  
  
<source lang=text>
+
<source lang="text">
 
20.0
 
20.0
 
30.0
 
30.0
</source>
+
</source>  
  
VJET launcher automatically loads any js files included using vjo.needs
+
VJET launcher automatically loads any js files included using vjo.needs  
  
=== using simple js with vjojs class ===
+
=== using simple js with vjojs class ===
  
MyProject/src/foo/MyClass.js
+
MyProject/src/foo/MyClass.js <source lang="javascript">
<source lang=javascript >
+
 
vjo.ctype('foo.MyClass') //< public
 
vjo.ctype('foo.MyClass') //< public
 
.protos({
 
.protos({
Line 83: Line 76:
 
})
 
})
 
.endType();
 
.endType();
</source>
+
</source>  
  
MyProject/src/foo/usingbar.js
+
MyProject/src/foo/usingbar.js <source lang="javascript">
<source lang=javascript >
+
 
vjo.needs("foo.MyClass")
 
vjo.needs("foo.MyClass")
 
foo.MyClass().foo(20);
 
foo.MyClass().foo(20);
 
foo.MyClass().foo(30);
 
foo.MyClass().foo(30);
</source>
+
</source>  
  
run as vjet application yields
+
run as vjet application yields  
  
<source lang=text>
+
<source lang="text">
 
20.0
 
20.0
 
30.0
 
30.0
</source>
+
</source>  
  
=== using vjojs main with vjo class dependencies ===
+
=== using vjojs main with vjo class dependencies ===
  
MyProject/src/foo/MyClass.js
+
MyProject/src/foo/MyClass.js <source lang="javascript">
<source lang=javascript >
+
 
vjo.ctype('foo.MyClass') //< public
 
vjo.ctype('foo.MyClass') //< public
 
.protos({
 
.protos({
Line 111: Line 102:
 
})
 
})
 
.endType();
 
.endType();
</source>
+
</source>  
  
MyProject/src/foo/Main.js
+
MyProject/src/foo/Main.js <source lang="javascript">
<source lang=javascript >
+
 
vjo.ctype('foo.Main') //< public
 
vjo.ctype('foo.Main') //< public
 
.needs("foo.MyClass")
 
.needs("foo.MyClass")
Line 125: Line 115:
 
})
 
})
 
.endType();
 
.endType();
</source>
+
</source> run as vjet application yields  
run as vjet application yields
+
  
<source lang=text>
+
<source lang="text">
 
20.0
 
20.0
 
30.0
 
30.0
</source>
+
</source>  
 
+
=== TODO ===
+
 
+
VJET has more runtime / debug support which is not yet polished...
+
-  Support needs comment as dependency
+
-  Debugging JS
+
- Running Js runner with vjojs and java
+
- Debugging JS in Web browser
+
  
 +
=== TODO<br> ===
  
 +
*Support needs comment as dependency
 +
*Debugging JS
 +
*Running Js runner with vjojs and java
 +
*Debugging JS in Web browser
  
 +
<br>
  
Tested with Indigo SR2 and Juno SR1 versions of Eclipse.
+
<br> Tested with Indigo SR2 and Juno SR1 versions of Eclipse.

Revision as of 15:31, 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);

run as vjet application yields

20.0
30.0

using vjojs main with vjo class dependencies

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/Main.js
vjo.ctype('foo.Main') //< public
.needs("foo.MyClass")
.props({
	//>public void main(String... args) 
	main : function(args){
		foo.MyClass().foo(20);
               foo.MyClass().foo(30);
	}
})
.endType();
run as vjet application yields
20.0
30.0

TODO

  • Support needs comment as dependency
  • Debugging JS
  • Running Js runner with vjojs and java
  • Debugging JS in Web browser



Tested with Indigo SR2 and Juno SR1 versions of Eclipse.

Copyright © Eclipse Foundation, Inc. All Rights Reserved.