How to put my own class into JsObject?

Sep 1, 2011 at 3:31 AM

I want to create a global variable with a member variable not known at compile time.

For example, I have a C# class Dog which I want to essentially do the following:

jsObject["animal"] = new Dog(); // Compile error because Dog is not JsInstance

jint.SetParameter("globals", jsObject);

Then in the javascript code, I want:;

(foo is a method of Dog).

Again, I don't know what "animal" will be at compile time.



Sep 1, 2011 at 6:36 AM

Use JintEngine.Global.WrapClr(Object) method to create a JsInstance from a CLR object

jsObject["animal"] = jint.Global.WrapClr(new Dog());