Why globalThis instead of something intuitive like globalObject, systemGlobal, or globalEntity?

Boris Zbarsky bzbarsky at mit.edu
Mon Oct 7 20:11:55 UTC 2019

On 10/7/19 1:56 PM, #!/JoePea wrote:
> Who's going to write code like that anyways?

In the general form of "function from a navigated-away-from document 
runs because it's called by some script from outside the document", I've 
seen this come up a number of times in web browser bug reports.

> Everyone's moving to ES modules, where `this` for accessing the global
> is just `undefined`.

It's not just "this".  The same thing applies to "window", "self", etc, 
etc.  There is no way to actually get your hands on the global object 
explicitly in a DOM Window scope: you always get the WindowProxy instead.

> It's highly unlikely that any concept other than
> "global object" will ever be conceived by the vast majority of users,
> especially future users.

Well, the thing that globalThis returns is NOT the global object, and 
telling people that it is will just confuse them when it behaves in a 
way they don't expect.


More information about the es-discuss mailing list