Take the 2-minute tour ×

I am executing a third party javascript file in the RhinoScriptEngine. The file contains references to methods in "this". i.e. this.getField. The file is written with the expectation that "this" is some object other than the js Window object. So now when I run the script I'm getting this error:

Cannot find function getField in object [object Global]

Using the Java ScriptEngine (Rhino), how can I change the object "this" is referring to? Thanks!

Generally, I can call something like, scriptEngine.eval(script). This works great as long as there are no references to some global "this" object. I'd like to do something similar, but where I can define what "this" is.

share|improve this question
In web browsers, there's .call, not sure if it's the same in Rhino. –  Rocket Hazmat Apr 10 '12 at 15:32
Does this answer help? –  squint Apr 10 '12 at 17:05
It is similar to the possible duplicate above, but the solution that is closest to what I was looking for is this: stackoverflow.com/a/2554033/1324406. Thanks for your help! –  Amber Apr 10 '12 at 22:00
add comment

Your Answer



Browse other questions tagged or ask your own question.