1

The last version of jxBrowser brings the createObject() method in JSContext. I´d like to create a String (or other types) directly from java. How can I use the createObject method to do that?

I´m able to create an empty object without problem and even set it´s property, but I don´t know how to create a String or Array or any other type.

Thanks for any help!

4

2 回答 2

1

现在 JSContext 只允许从 Java 创建 JavaScript 对象。如果您需要创建一个字符串或数组,那么您可以使用以下方法:

JSValue value = browser.executeJavaScriptAndReturnValue("'this is my string'");
JSString jsString = value.asString();
于 2016-10-07T11:17:43.060 回答
0

我只是试图破解它......

正在做:

obj = jscontext.createObject()
obj.setProperty("constructor", Array)
obj.setProperty("__proto__", Array)

将创建一个对象,其行为类似于 javascript 中的数组(如果在此对象上调用 eval),尽管它不是 JSArray。

这种方法不适用于字符串。我猜 String 是一种特殊类型的构造函数。

于 2016-10-07T14:57:07.477 回答