【问题标题】:Problems in ctor of Jint in .NET 4.5.NET 4.5 中 Jint 的 ctor 问题
【发布时间】: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


【解决方案1】:

我想我破解了它:

engine.Execute(@"function Panel(objectBehind)
{
   this.objectBehind = objectBehind;
   return this;//bit strange and unusual pattern
}
Panel.prototype.objectBehind;");

JsValue resultCTor = engine.Invoke("Panel", 1);
JsValue objectBehind = engine.GetValue(resultCTor, "objectBehind");

【讨论】:

    猜你喜欢
    • 2013-04-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-11-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-12-27
    相关资源
    最近更新 更多