String script = "function abc(x,y) {return x+y;}"
+ "function def(u,v) {return u-v;}";Context context = Context.enter();try {
ScriptableObject scope = context.initStandardObjects();
context.evaluateString(scope, script, "script", 1, null);
Function fct = (Function)scope.get("abc", scope);
Object result = fct.call(
context, scope, scope, new Object[] {2, 3});
System.out.println(Context.jsToJava(result, int.class));} finally {
Context.exit();}[@more@]
来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/26273052/viewspace-1059811/
,如需转载,请注明出处,否则将追究法律责任。