Home > Web Front-end > JS Tutorial > Detailed explanation of Javascript window object_Basic knowledge

Detailed explanation of Javascript window object_Basic knowledge

WBOY
Release: 2016-05-16 16:31:30
Original
1517 people have browsed it

First look at our source code.

Copy code The code is as follows:




                                                                                                                                                                                             



Run the code and output this == window ?true , which means Window== window , is this really the case?

In order to understand the relationship between them, we continued to test


Copy code

Mozilla Firefox :



From the output results we can deduce,


Copy code

The code is as follows: this points to the Window object; this is also equal to the window object; window also points to the Window object;
Window points to Window{}, which is an object provided by the browser;
Window is not equal to window;


Why is this happening?

We view the structure of the Window object in the browser console;


It turns out that the Window object contains some APIs implemented by browser manufacturers, such as the standard sessionStorage in html5;
It also has a window attribute, and the value of this attribute points to the Window object;
My understanding: The Window object serves browser manufacturers. We cannot directly operate the properties of the Window object. New APIs added by Window will be reflected in the window object;
The properties we operate on window will be reflected in the Window object.
For example, define a global variable window.a = 'aaa';

All JavaScript objects exist in a running environment. This running environment itself is also an object, called a "top-level object". This means that all objects in JavaScript are subordinate to the "top-level object". Different running environments have different "top-level objects". In the browser environment, this top-level object is the window object.

All global variables of the browser environment are properties of the window object.

Window can be understood as JavaScriptContext context environment.

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template