java – Window,Document vs. $wnd,$doc

I know that the following is some of the same in GWT:

Window and $wnd
Document and $doc

Is there any difference except that the first is for Java and the second is for jsni (JavaScript)?

Solution

Window is a static method of many classes. You can use it to get or set some properties of the browser window, but in fact it is not a native browser window object The final implementation of these methods is the jsni block, which uses the $wnd variable to set / get these attributes Like window Like alert (), its implementation is $wnd alert(). Notice that window Java cannot access all the contents in the browser window object, such as window Console et al

GWT uses $wnd instead of window, because compiled code is usually executed in iframe. In this case, window will refer to iframe window and $wnd will refer to parent window$ The same is true for DOC, which is a reference from iframe to the parent document

On the other hand, document is a Java class that extends JavaScript object, which means that it is an overlay type, which basically means that it is a special wrapper for native JavaScript objects. It does not modify the underlying JavaScript, but adds a set of Java methods to interact with it It can be safely cast when passed to jsni

In short, although document and $doc are different in the Java world, they are the same when compiling them. Otherwise, window is not a superposition of $wnd, it is just a way to access some methods of browser window

Although GWT compiled code is delegated to native JS objects and methods, don't try to find similarities between JS and Java objects GWT designs an API to develop Ajax applications using a set of Java objects, widgets, patterns, etc Some objects and methods are named the same way, but almost all APIs are different However, other projects compile Java into JavaScript. The two worlds have strict parallelism between st-js, while GWT provides an experimental library called elemental, whose API is almost the same as JavaScript (it is only applicable to chrome)

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>