File tree 2 files changed +12
-2
lines changed
2 files changed +12
-2
lines changed Original file line number Diff line number Diff line change 1
- var fun = function ( name ) {
1
+ var fun1 = function ( name ) {
2
2
print ( 'Hi there from Javascript, ' + name ) ;
3
3
return "greetings from javascript" ;
4
+ } ;
5
+
6
+ var fun2 = function ( object ) {
7
+ print ( "JS Class Definition: " + Object . prototype . toString . call ( object ) ) ;
4
8
} ;
Original file line number Diff line number Diff line change 4
4
import javax .script .ScriptEngine ;
5
5
import javax .script .ScriptEngineManager ;
6
6
import java .io .FileReader ;
7
+ import java .time .LocalDateTime ;
8
+ import java .util .Date ;
7
9
8
10
/**
9
11
* Calling javascript functions from java with nashorn.
@@ -17,8 +19,12 @@ public static void main(String[] args) throws Exception {
17
19
engine .eval (new FileReader ("res/nashorn1.js" ));
18
20
19
21
Invocable invocable = (Invocable ) engine ;
20
- Object result = invocable .invokeFunction ("fun " , "Peter Parker" );
22
+ Object result = invocable .invokeFunction ("fun1 " , "Peter Parker" );
21
23
System .out .println (result );
24
+
25
+ invocable .invokeFunction ("fun2" , new Date ());
26
+ invocable .invokeFunction ("fun2" , LocalDateTime .now ());
27
+ invocable .invokeFunction ("fun2" , new Person ());
22
28
}
23
29
24
30
}
You can’t perform that action at this time.
0 commit comments