On Apr 19, 11:34 am, Reinier Kip <[email protected]> wrote:
> Hi,
>
> I am trying to map existing JavaScript 'classes' in the document to
> client-side Java classes. Take this example JS 'class':
>
> Alerter = function() {
> this.alert = function(msg) {
> alert(msg);
> };
>
> };
>
> Mapping this to a client-side Java class currently means:
>
> class Alerter extends JavaScriptObject {
>
> public static final native Alerter create() /*-{
> return { impl: new Alerter() };
> }-*/
You have to write $wnd.Alerter() (unless you only have to support the
"xs" linker), and why storing it in a property ("impl") of an
otherwise useless object?
> public final native void alert(String msg) {
> this.impl.alert(msg);
> // or for repeatability: return this.impl.alert.apply(this,
> arguments);
> }
>
> }
>
> I feel it should be possible to do this in Java:
>
> (...)
> public static final native Alerter create() /*-{
> return new Alerter();}-*/
>
> public final native void alert(String msg);
> (...)
>
> This directly maps the Java declaration to the JavaScript
> implementation.
Apart from the "direct mapping", this is already possible (using
native void alert(String msg) /*-{ this.alert(msg); }-*/; )
AFAICT, this "direct mapping" was part of the original design but no-
one took the time to implement it, as it's just syntactic sugar (and
the Google Plugin for Eclipse will now autocomplete it for you!)
See: http://code.google.com/p/gwt-api-interop/ which I believe heavily
inspired the current design of JSOs in GWT proper.
--
You received this message because you are subscribed to the Google Groups
"Google Web Toolkit" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/google-web-toolkit?hl=en.