Thank you Ray. This is a good explanation. It should be added to the docs.
Best
Michael
Am Mittwoch, 29. Oktober 2014 16:44:42 UTC+1 schrieb Ray Cromwell:
>
> Whether you use $wnd.SomeJsObject or SomeJsObject depends on the
> following:
> 1) whether you want 'instanceof' to only work on objects that come
> from the host page
> 2) whether or not you're going to extend/subtype JS objects
>
> In most cases, you want "$wnd.SomeJsObject", however there are cases
> where you don't
>
> 1) if you loaded some hand written JS into 'window' instead of $wnd
> 2) if you are referring to inbuilt native JS objects like Window or
> HTMLDivElement
>
> If you do the following
>
> @JsType(prototype="$wnd.Window")
> interface Window {
> ...
> }
>
> Window w = someIframe.window();
>
> Then w instanceof Window => false. Why? Because the GWT compiler will
> emit "w instanceof $wnd.Window", but your checking for Window objects
> from ANY location.
>
>
> So you see, a prefix of $wnd leads to an ABSOLUTE instanceof operator.
> If you don't specify $wnd, then the instanceof check is relative. So
> for example, it will just check if your constructor is 'Window', no
> matter which context where it came from.
>
> In general, native DOM elements == no $wnd prefix, JS libraries loaded
> in host page == $wnd prefix
>
>
> On Wed, Oct 29, 2014 at 7:04 AM, confile
> <[email protected] <javascript:>> wrote:
> > thank oyu Jens. What about my first question:
> >
> > Is it @JsType(prototype="SomeJsObject") or
> > @JsType(prototype="$wnd.SomeJsObject") ?
> >
> > Best
> > Michael
> >
> > Am Mittwoch, 29. Oktober 2014 14:45:33 UTC+1 schrieb Jens:
> >>>
> >>> Consider an interface
> >>>
> >>> @JsType
> >>> interface Test {
> >>> void do();
> >>> }
> >>>
> >>> How do I instantiate such an interface?
> >>
> >>
> >> For now you need to use a JSNI factory method. May it be in a static
> inner
> >> class or a dedicated factory class for all your JsTypes.
> >>
> >> With GWT 3.0 (and Java8 support) you can use a static factory method on
> >> the interface which uses GWT.jsni() or GWT.js() or whatever name that
> >> special GWT method will have. So in GWT 3.0 it will probably look like:
> >>
> >> @JsType
> >> interface Test {
> >> static Test create() { return GWT.js("new Test()"); }
> >> void do();
> >> }
> >>
> >>
> >> -- J.
> >
> > --
> > You received this message because you are subscribed to the Google
> Groups
> > "GWT Contributors" group.
> > To unsubscribe from this group and stop receiving emails from it, send
> an
> > email to [email protected]
> <javascript:>.
> > To view this discussion on the web visit
> >
> https://groups.google.com/d/msgid/google-web-toolkit-contributors/a8612613-de28-4413-926f-ed97086436fa%40googlegroups.com.
>
>
> >
> > For more options, visit https://groups.google.com/d/optout.
>
--
You received this message because you are subscribed to the Google Groups "GWT
Contributors" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/google-web-toolkit-contributors/89359bef-175d-4a96-9362-787fed32888d%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.