Mozilla Rhino: Different ways of adding Java object to scope
I've got this piece of Java code with embedded Rhino (irrelevant bits omitted):
Context cx = Context.enter();
Scriptable scope = cx.initStandardObjects();
scope.put("foo", scope, Context.toObject(foo, scope));
ScriptableObject.putProperty(scope, "bar", Context.javaToJS(bar, scope));
where foo
extends ScriptableObject
and bar
is just a POJO without a parent.
Is there, in this particular case, any difference between the way foo
and bar
are added, or is the result the same?
I tried consulting documentation but I couldn't find any answer. Eventually I 开发者_如何学运维just looked up the source code (rhino1_7R1 version) and my guess is it doesn't really matter in that scenario. Or does it?
I think you are correct. I believe I've been on the same code-reading expedition as you and reached the same conclusion. The top-level objects of the scope are the same thing as the properties of the scope.
精彩评论