2009/7/6 Koen Deforche <[email protected]>:
>> Is there a way of defining "global" functions that I can call from my
>> JSlots (or doJavaScript) - of course I can reverse engineer the way Wt
>> calls JSlots - but it would be good to have thoughts on the "official"
>> best practice.
>
> There are several public, but not documented methods, for this (which
> are indeed also by JSlot and several widgets). You might as well use
> these until we have decided on the proper API for this. The reason for
> them being undocumented is that I am still a bit unsure of the proper
> signature for it (all in all it would be nice if Wt provided better
> support for JavaScript than it does now). Another problem is that I am
> unsure about possible JavaScript circular reference memory leaks with
> the current API.
>
> WApplication::declareJavaScriptFunction(): declares a "global" function:
> e.g. wApp->declareJavaScriptFunction("myfoo", "function(a, b) { return
> a + b; }");
>
> WApplication::javaScriptClass(): the scope for "global" functions
> (which is currently fixed to "Wt", but which we will allow to be
> customized, so that a single web page can simultaneously have
> different Wt applications in it, using the widget set mode.
>
> A call to the declared javascript function thus is:
> wApp->javaScriptClass() + ".myfoo(4, 5);"
>
> It's all very verbose as well -- perhaps that could be improved before
> deciding on a public API as well.

Thanks for the info.

The other alternative I was considering was using the
WApplication::require() function to load a file with all the required
javascript functions in it. I haven't tried it out so am not clear
what the library should look like (just a bunch of functions I guess -
but I am not too certain of name scope). This has the advantage of
separating all the javascript code out.

------------------------------------------------------------------------------
_______________________________________________
witty-interest mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/witty-interest

Reply via email to