【发布时间】:2015-01-01 22:44:05
【问题描述】:
我使用的是 Sebastien Ros 的 4.5 .NET 版本 Jint。 还有javascript原型对象,我想用一个对象来调用javascript原型构造函数。
我在这里遇到了一些问题。 像这样的:
function Panel(objectBehind)
{
log(objectBehind);
}
Panel.prototype.objectBehind;
1) 如何创建一个新的 Panel 对象,调用 ctor 参数? 我已经走到这一步了:
engine.Execute(script);
engine.Execute("new Panel();");
JsValue val = engine.GetCompletionValue();
但是 ctor 参数当然是空的。
2) 假设我想在新的 java 原型对象上设置 objectBehind 属性,这将如何在 JsValue 对象上工作?
3)我可能可以使用命名变量,然后调用poperty,但是我需要添加命名变量:
engine.Execute(script);
engine.Execute("var myPanel = new Panel();");
//do the set prop on mypanel from here.
【问题讨论】:
-
我想我破解了:engine.Execute(@"function Panel(objectBehind) { this.objectBehind = objectBehind; return this;//有点奇怪和不寻常的模式} Panel.prototype.objectBehind;" ); JsValue resultCTor = engine.Invoke("Panel", 1); JsValue objectBehind = engine.GetValue(resultCTor, "objectBehind");
标签: constructor .net-4.5 jint