Mozilla Rhino:将 Java 对象添加到范围的不同方法
我有这段带有嵌入式Rhino的Java代码(省略了不相关的位):
Context cx = Context.enter();
Scriptable scope = cx.initStandardObjects();
scope.put("foo", scope, Context.toObject(foo, scope));
ScriptableObject.putProperty(scope, "bar", Context.javaToJS(bar, scope));
其中foo
扩展了ScriptableObject
和bar
只是一个POJO,没有一位家长。
在这种特殊情况下,foo
和 bar
的添加方式是否有任何区别,或者结果是否相同?
我尝试查阅文档,但找不到任何答案。最终我只是查找了源代码(rhino1_7R1 版本),我的猜测是在这种情况下这并不重要。或者确实如此?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我认为你是对的。我相信我和你经历过同样的代码阅读探险并得出了同样的结论。作用域的顶级对象与作用域的属性是相同的。
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.