Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JavaScript global object and the global scope

  1. Which object in the web browser is the global object?
  2. Is the global scope the scope provided by the global object? If not, then where is the global scope found?
like image 570
Jahlom Avatar asked Jan 17 '14 11:01

Jahlom


2 Answers

In a browser enviroment, the Window is considered the global scope.

  • The Window

The window object implements the Window interface, which in turn inherits from the AbstractView interface.
Some additional global functions, namespaces objects, interfaces, and constructors, not typically associated with the window, but available on it, are listed in the JavaScript Reference and DOM Reference.

The window object represents the window itself.
The document property of a window points to the DOM document loaded in that window.
A window for a given document can be obtained using the document.defaultView property.

In a tabbed browser, such as Firefox, each tab contains its own window object (and if you're writing an extension, the browser window itself is a separate window too.
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 window and not to the specific tab the window object belongs to. Generally, anything that can't reasonably pertain to a tab pertains to the window instead.

like image 95
adeneo Avatar answered Oct 30 '22 16:10

adeneo


  1. the global object is called window
  2. yes , the global scope is provided by window, so u can get any global variable with window.varible
like image 45
Vlad Nikitin Avatar answered Oct 30 '22 16:10

Vlad Nikitin