Bind method call in JavaScript script in Java Scripting
- use
engine.createBindings()
to make a Bindings object; put an object exposing your method into the bindings with some name:
Bindings b = engine.createBindings();b.put("api", yourApiObject);engine.setBindings(b, ScriptContext.ENGINE_SCOPE);
Then in JavaScript there'll be a global "api" object you can call:
api.method1( "foo", 14, "whatever" );
The facility is easy to use, but be careful with what you pass back and forth; it doesn't do that much to convert JavaScript types to Java types.