Window, Document vs. $ wnd, $ doc

I know that in GWT the same thing:

Window and $wnd Document and $doc 

Are there any differences besides the former being used in Java and the latter in JSNI (JavaScript)?

+6
source share
1 answer

Window is a class of many static methods that you can use to get or set certain properties of a browser window, but it's actually not your own browser window object. These method implementations are ultimately JSNI blocks that use the $wnd variable to set / get these properties. Like Window.alert() , whose implementation will be $wnd.alert() . Please note that Window.java does not have access to everything in the browser window window, for example window.console , etc.

GWT uses $wnd instead of Window , because the compiled code runs fine in the iframe, and in this context, Window will refer to the iframe, and $wnd will refer to the parent window. The same thing happens with $doc , which is the iframe link to the parent document.

On the other side of the Document there is a java class that extends JavaScriptObject , which means that it is Overlay , which basically means that it is a special wrapper for its own javascript object, it does not change the underlying JavaScript, but adds a set of java methods to interact with it . It can be used safely when going to jsni.

In general, although Document and $doc do not match in the Java world, when they are compiled, they will be the same, otherwise Window is not an overlay of $wnd , it is just a way to access certain methods of the browser window.

Although the GWT compiled code delegates its own js objects and methods, do not try to find the similarities between js and java objects. GWT has developed an API for developing ajax applications using a set of java objects, widgets, templates, etc. Some objects and methods are called the same, but almost the API is different. However, there are other projects that compile java into javascript, which has a tight parallelism between the two worlds, such as ST-JS , and GWT provides an experimental library called Elemental , whose API is almost identical to javascript (it is available only for Chrome).

+11
source

Source: https://habr.com/ru/post/956324/


All Articles