javascript - What is the difference between Object constructor and Global Object -


i confused "global object" (window) , "object" constructor in js. confusing part when read similar sentences, 1 while reading scopes , other 1 when reading objects , inheritance in javascript :

  1. all objects in javascript descended object; objects inherit methods , properties object.prototype, although may overridden.
  2. global variables automatically properties of global object (window in browsers, etc.), ..............

what know : know objects in javascript inherited "object" root object! objects in javascript inherited prototype, including prototype of built-in objects "array".

array.prototype.__proto__===object.prototype  //true 

on other hand when talking scopes, have called global scope root scope called global object. , :

> window.prototype.__proto__ result : eventtarget { addeventlistener=addeventlistener(),    removeeventlistener=removeeventlistener(),  dispatchevent=dispatchevent(),  more...} 

and

> window.__proto__  result : window { addeventlistener=addeventlistener(),  removeeventlistener=removeeventlistener(),  dispatchevent=dispatchevent(),  more...} 

i know 2 totally different issues. what? leads which? who?

is there relationship between them?

the object constructor function creates (or converts primitives to) objects.

object.prototype property of object function, defines root of built-in prototype chain. most javascript objects inherit it, though possible create objects not.

the global object place global variables live. objects, inherits object.prototype (though more of de facto standard; spec doesn't require it, engines anyway). because object constructor bound global variable, lives here.

note in different runtime contexts, the global object can inherit other objects, provided continues satisfy usual requirements. in browsers, example, global object inherits either window (ordinary contexts) or workerglobalscope (web workers).

in many contexts, global object bound global variable. historically browsers called window in ordinary contexts, self (originally part of web workers) standardized in html5. global variables, these names become properties of global object: in ordinary browser, call window.self.window.self.window if wanted to.


Comments

Popular posts from this blog

powershell Start-Process exit code -1073741502 when used with Credential from a windows service environment -

twig - Using Twigbridge in a Laravel 5.1 Package -

c# - LINQ join Entities from HashSet's, Join vs Dictionary vs HashSet performance -