File tree Expand file tree Collapse file tree 2 files changed +12
-2
lines changed
Expand file tree Collapse file tree 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 ) {
22 print ( 'Hi there from Javascript, ' + name ) ;
33 return "greetings from javascript" ;
4+ } ;
5+
6+ var fun2 = function ( object ) {
7+ print ( "JS Class Definition: " + Object . prototype . toString . call ( object ) ) ;
48} ;
Original file line number Diff line number Diff line change 44import javax .script .ScriptEngine ;
55import javax .script .ScriptEngineManager ;
66import java .io .FileReader ;
7+ import java .time .LocalDateTime ;
8+ import java .util .Date ;
79
810/**
911 * Calling javascript functions from java with nashorn.
@@ -17,8 +19,12 @@ public static void main(String[] args) throws Exception {
1719 engine .eval (new FileReader ("res/nashorn1.js" ));
1820
1921 Invocable invocable = (Invocable ) engine ;
20- Object result = invocable .invokeFunction ("fun " , "Peter Parker" );
22+ Object result = invocable .invokeFunction ("fun1 " , "Peter Parker" );
2123 System .out .println (result );
24+
25+ invocable .invokeFunction ("fun2" , new Date ());
26+ invocable .invokeFunction ("fun2" , LocalDateTime .now ());
27+ invocable .invokeFunction ("fun2" , new Person ());
2228 }
2329
2430}
You can’t perform that action at this time.
0 commit comments