Why window object in the browser points to window object. Mozilla Website states the reason as
The point of having the window property refer to the object itself was (probably) to make it easy to refer to the global object (otherwise you'd have to do a manual
var window = this;
assignment at the top of your script).
So, my question is, how to infinitely point an object to object and how that helps to avoid doing var window = this;
window.window // returns window object
window.window.window // also returns an window
The window is the global object in the web browser. The window object exposes the functionality of the web browser. The window object provides methods for manipulating a window such as open() , resize() , resizeBy() , moveTo() , moveBy() , and close() .
window. ABC = "abc"; //Visible outside the function var ABC = "abc"; // Not visible outside the function. If you are outside of a function declaring variables, they are equivalent.
Definition and Usage. The open() method opens a new browser window, or a new tab, depending on your browser settings and the parameter values.
window is the execution context and global object for that context's JavaScript. document contains the DOM, initialized by parsing HTML. screen describes the physical display's full screen.
window.window or window.window.window and so on, that's not an implementation, that's a side-effect
consider this
var win = {};
win.win = win;
now
win.win === win
and
win.win.win === win
so what they could have done is like
var window = this;
which is actually same as
this.window = this;
because all the variables declared in global scope are properties of this, so doing such thing resulted in window.window.window.window....
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With