0

I'm using Jint, the 4.5 .NET version, of Sebastien Ros. And javascript prototype objects, and I want to call the javascript prototype constructor with an object.

I run into some problems here. Someting like this:

function Panel(objectBehind)
{
  log(objectBehind);
}
Panel.prototype.objectBehind;

1) How do I create a new Panel object, calling the ctor parameters? I got this far:

 engine.Execute(script);
 engine.Execute("new Panel();");
 JsValue val = engine.GetCompletionValue();

But then the ctor argument is empty, of course.

2) Suppose I want to set the objectBehind property on the newed java prototype object, how would that work on the JsValue object?

3) I probably could use a named var, and then call the poperty, but then I need to add named vars:

       engine.Execute(script);
       engine.Execute("var myPanel = new Panel();");
       //do the set prop on mypanel from here.
Ahmet Kakıcı
  • 6,294
  • 4
  • 37
  • 49
Roland Roos
  • 1,003
  • 10
  • 4
  • I think I cracked it: 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"); – Roland Roos Jan 04 '15 at 22:14

1 Answers1

2

I think I cracked it:

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");
Roland Roos
  • 1,003
  • 10
  • 4