Hi Bojan,
Thanks for the reply.
This started out mainly as me trying to use JavaScript closures and anonymous functions as a quasi-malloc.
Some of the problems are: -
1) You can't get a worthwhile (to a VMS 3GL routine) handle on them
2) There are grave doubts about them no longer being referenced and being garbage-collection candidates
3) I really wished they'd work as I think they're really really sexy!
See attached for a tiny example of what I'd hope to achieve with closures and emulating ASTs + Parameters.
Enter something in one of the fields and move off to the other one to see the results. (Try multi-tab and multi-browser instance as well)
Anyway we are where we are as probably best followed at: -
http://groups.google.com/group/comp.lang.java.programmer/browse_frm/thread/06e807a645ea8e78#(Sorry for the multi-posting)
But to answer some of your points: -
> If I am correct, all JavaScript objects
> are wrapped with the JSObject when they
> are passed to Java methods.
Really?
> before calling the Applet method wrap all
> your functions in a single object (AJAX
> does the same) and pass this object to the
> Applet method.
That was the plan but who'd maintain a reference to it? That's where I came to the Array solution like you (but on the JavaScript side instead)
>(in yours example "public void javaMethod
> (String jsNum, String jsFunc)" will
> probably be "public void javaMethod
> (JSObject request)").
Well spotted - changed in the attached.
> c) If you have more than one response you
> probably know which response belong to the
> specific request and when you are finished
> by this request. Simply remember the
> request (probably a simple Hashtable can
> do all the work) and use it until you have
> some responses.
I can rely on FIFO so it makes things a bit easier.
> e) Probably the JSObject which wrapp the
> JavaScript object will take the reference.
> If this is not true and the object can be
> garbage-collected put this object in an
> array so JavaScript will reference the
> object and when you are finished remove it
> from the array.
Bummer, eh.
Hold on! Looking at your example, I think I understand you now. Are you saying: -
a) Don't have to reference any objects or closures on the JavaScript side 'cos Java will honour the complex Object and it will be maintained in the Java LinkedList?
b) We somehow add/append a ID/SerialNumber or whatever to check against incoming replies?
c) That a variable function name (also sent/returned with the messages) is then called with the Complex Object and the message body as it's parameters?
d) That function can reference a further internal callback if need be?
e) Everyone's a winner; chickens for dinner?
Sounds good! I'm off to sleep on it - Thanks!
Cheers Richard Maher
PS. I think we're still stuck with no one on the JS side referencing any of these lovely complex objects and no gurantee of their longevity? Any takers?