Creating objects from C# to hand to JS

42 views
Skip to first unread message

Russ

unread,
Jan 12, 2012, 5:57:09 PM1/12/12
to IronJS
Does anyone happen to have an example of creating an object instance
with property values set to hand off to JS? Especially if the object
instance itself contains other JS objects, all of which have to be
constructed on the C# side.

I'm messing with the wiki example and my CLR type shows up on the JS
side just fine but I can't seem to pass any instances into JS
functions.

Russ

unread,
Jan 12, 2012, 6:01:25 PM1/12/12
to IronJS
I am a dork; for reference, here is what you can do:

public static MyClass CreateInstance(CSharp.Context context,
OtherClass node)
{
var globalPrototype = context.GetGlobal("MyClass");
var prototype = globalPrototype.Unbox<CommonObject>();
return new MyClass(context.Environment,
prototype.GetT<CO>("prototype")) { Node = node };
}

which will return an instance of MyClass that itself contains a
property called Node that is an instance of OtherClass.
Reply all
Reply to author
Forward
0 new messages