Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- `// Where script returns a 'function () {}' object.
- final String script = someScript;
- // ScriptUtils comes from jdk.nashorn.api.scripting.ScriptUtils
- final ScriptObjectMirror som = ScriptUtils.unwrap(engine.eval(source ));
- /* This object will be created once and kept around to avoid re-creating
- it through ScriptObjectMirror#call varargs. */
- Object[] args = something;
- // Then calling the js function object with itself as 'this'.
- som.call( som, args );`
- `// 'context' is a Java object.
- function (context) {
- let id = context.ownerId;
- let data = context.dataFor(id);
- // do things with data and context.
- }`
Add Comment
Please, Sign In to add comment