On Fri, May 29, 2009 at 11:16 AM, John Tamplin <[email protected]> wrote:
> On Fri, May 29, 2009 at 10:42 AM, Vitali Lovich <[email protected]> wrote: > >> 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). >> > > That's not legal Java, so it would defeat your purpose of getting IDE > support/etc. > I know. > The way you get a method reference in pure Java is via reflection, which in > general is not feasible though there have been some discussions of allowing > it when everything can be evaluated at compile time (ie, all constants for > classes and method/field names) -- even that seems to be a long way away > however. > How about through GWT.create? Then it uses reflection to supply the actual function. Might be limited to JSNI functions unless you can compile code fragments. > > > For JSNI syntax checking, you can use the Google Eclipse plugin which > supports a number of JSNI features. > I haven't actually looked at the plugin yet. > > > >> 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. >> > > The only thing I think would be feasible here would be to add some sort of > call method on JavaScriptObject that would treat it as a torn-off function. > Why not create a JsFunction class that extends from JavaScriptObject to represent a JS lambda function. However, since you can't have polymorphic dispatch on JSOs, that would > reserve whatever name was chosen from all subclasses, so it would have to be > something unlikely to collide. I'm not sure what you mean here. Why would you need to reserve a name? > > -- > John A. Tamplin > Software Engineer (GWT), Google > > > > --~--~---------~--~----~------------~-------~--~----~ http://groups.google.com/group/Google-Web-Toolkit-Contributors -~----------~----~----~----~------~----~------~--~---
