On Fri, May 29, 2009 at 9:42 AM, John Tamplin <[email protected]> wrote:
> On Thu, May 28, 2009 at 8:18 PM, Vitali Lovich <[email protected]> wrote: > >> It would be nice if there was a way to wrap Java methods with an opaque >> Javascript function object so that you could pass them around in the native >> code (obviously there are issues with compiler optimizations in this case). >> > > You can do this now -- in a JSNI method: > > static void bar(int arg) { ... } > > var f = @org.example.Foo::bar(I); > I was thinking more along the lines of JavascriptFunction foo = MyClass.bar.method or something like that. That way, you could do dynamic function invocation without ever needing JSNI. It's also a lot easier to write that code, maintain it, & it's IDE friendly, meaning no typos & syntax checking (which is a major strength of GWT). > > You can then pass/return it to Java/JSNI code as a JavaScriptObject, or > directly to external Javascript that looks for a function. > > >> Ideally, you would be also able to execute any Javascript function object >> from within Java code, although that does present some problems. >> > > You have to have a JSNI method to do this now: > > private static native JavaScriptObject callFunc(JavaScriptObject func, int > arg) /*-{ > func(arg); > }-*/; Yes - hence the feature request. I know it's non-trivial given that GWT follows Java convention & wraps varargs in an array which could cause problems for the JS. Just trying to get some feedback on whether or not it's a good idea. > > -- > John A. Tamplin > Software Engineer (GWT), Google > > > > --~--~---------~--~----~------------~-------~--~----~ http://groups.google.com/group/Google-Web-Toolkit-Contributors -~----------~----~----~----~------~----~------~--~---
