import org.mozilla.javascript.Context
import org.mozilla.javascript.Function
funrunScript(js: String, funcName: String, params: Array<Any>): Any {val rhino = Context.enter()
rhino.optimizationLevel =-1val scope = rhino.initStandardObjects()
rhino.evaluateString(scope, js,"runScript",1,null)val function = scope.get(funcName, scope)as Function
val result = function.call(rhino, scope, scope, params)return result
}
调用
val scriptStr="function test(one,two,three,four){return ''+one+two+three+four}"//获取结果val res=runScript(scriptStr,"test",arrayOf("a","b","c","d")).toString()