javascript - What is the difference between a global variables and attributes of the window object? -


I'm a bit confused with the Javascript window object For starters, consider the following two announcements:

  var imglobal = "I'm Global"; Window.imglobal = "I'm Global";  

As far as I understand it, it will be exactly the same (is it?) It can be reached in both cases as "Impossible" or "Window.imogloble". I do not understand why, why local declares variables, the following does not work:

  function imafunc () {var imavar = "I Variable "; Window.alert (imafunc.imavar); }  

So why is the following?

  var imavar = "I am a variable"; Window.alert (window.imavar);  

I stumbled upon using GWT; It seems that always have to refer to the window object ($ wnd), possibly because it is not a "real" window object but some kind of sandbox.

It becomes more confusing with this function, I know three ways to declare them:

prefix var myfunc = function () {window.alert (" Hello, World! "); } Window.myfunc = function () {window.alert ("hello, world!"); } Function myfunc () {window.alert ("hello, world!"); }

Is there any technical difference between these three methods?

About your observation:

While using GWT Stumbled upon this; It appears that there is always obviously to refer to the window object ($ wnd), possibly because it is not a "real" window object but some kind of sandbox.

The reason is that there is a need to always use its variable and function with $ wnd in GWTJNSI to ensure that you are reaching the variable from the window scope (host page) . The reason for this is that JSNi is run in an iframe, so without any $ wnd qualifier, any variable is resolved within the scope of iframe and does not fit the window, which you want


Comments