This project has moved and is read-only. For the latest updates, please go here.

Common functionality in custom derived ObjectInstances

Nov 6, 2011 at 1:01 PM

I need to add some common functionality to several custom ObjectInstances. Specifically, what I need is eventing.

What I want, is functionality so that I can write JS like so:

obj.listen('connect', function (param1, param2, paramN) {
    // Do something usefull
});

and on the C# side I would like to have a function that I can call like this:

this.Fire('connect', param1, param2, paramN);
Now, I have no problem with implementing the Listen and the Fire methods myself, but what I need is some way to to map this all together. Like, say I have a class SeverConnection for instance, that extends ObjectInstance. How would I go about adding the eventing-functionallity to that class (whithout having to manually implement it everywhere), so that it works both on the js side, and on the C# side?

Nov 6, 2011 at 9:09 PM

The documentation for interoping with JavaScript is here: http://jurassic.codeplex.com/wikipage?title=Exposing%20a%20.NET%20class%20to%20JavaScript&referringTitle=Documentation

I'm not quite sure what you mean when you say "whithout having to manually implement it everywhere".  Couldn't you just have a base class that inherits from ObjectInstance and has the desired functionality?

Nov 6, 2011 at 9:44 PM

I tried that, but PopulateFunctions don't go up trough inheritance-chain in C#, thus resulting in the js-code not working (obj.listen is not defined).

Nov 6, 2011 at 10:26 PM

Ah, I see your problem now.  See here for some discussion on this problem: http://jurassic.codeplex.com/discussions/273731  Does this solve your problem?