Jump to content

User:Bhaveshkasliwal/sandbox

From Wikipedia, the free encyclopedia

[1]

The Browser Object Model creates a tree-like hierarchy of objects, many of which provide properties and methods for the JavaScript programmer. The browser itself is represented by one object, called the window object. The window object is a global object that represents the currently open tab in the browser and is the first thing that gets loaded into the browser. All global JavaScript objects, functions, and variables automatically become members of the window object. Global variables are the properties and global functions are the methods of the window object. The properties and methods of the window object can be called directly and do not require the window prefix. But objects beyond the window object’s direct descendants, need to be preceded by the window object name. It is allowed to access document object directly but the children of document object need to be accessed through document object only.

The window object represents a window containing a DOM document; the document property points to the DOM document loaded in that window. A window object can be accessed through the document object using document.defaultView property. The window object implements the Window interface, which in turn inherits from the AbstractView interface. In tabbed browsers like Firefox, Chrome etc.; each tab contains its own window object. That is, the window object is not shared between tabs in the same window. Some methods, namely window.resizeTo and window.resizeBy apply to the whole browser window and not to the specific tab the window object it belongs to.[2] If an HTML document contains frames, the browser creates one window object for the HTML document and one additional window object for each frame.

Standard

[edit]

There is no standard for window objects. Every browser implements it as per their requirements but the core remains the same across all the browsers.

Use Cases

[edit]

Following are a few use cases for the window object:

  1. Accessing existing global variables.
  2. Protecting global variable from being shadowed by an inner scope variable.
  3. Built-in global variables – The built-in global variables are referred via window to denote that they are global.
  4. Window enables to check whether a variable is global or not.
  5. Creating things in global scope.

References

[edit]

Sources

[edit]
  1. ^ Eich, Danny Goodman with Michael Morrison ; with a foreword by Brendan (2007). JavaScript bible (6th ed. ed.). Indianapolis: Wiley. ISBN 9780470069165. {{cite book}}: |edition= has extra text (help)CS1 maint: multiple names: authors list (link)
  2. ^ "Window". Mozilla Developer Network. Retrieved 2016-09-11.