JavaScript's global object is now "globalThis"


Just noticed the name change today. Too much breaking the web :roll_eyes: by using just global so we’re left with globalThis (still stage 3 but almost there).

My first impression on the naming…

Related image


In what environment are you seeing globalThis? I’m on the latest Chrome Canary, and I don’t see it yet. Should check in Node?


I see it in Canary

Version 72.0.3604.0 (Official Build) canary (64-bit)



My mind only remembers the safe/guaranteed way to get this object in AS3:

var global = function() { return function() { return this }() }()


I see it now! Turns out my Canary was out-of-date :bug:


Were both functions needed?


In some contexts, I think so. In particular, I think if you were contextually inside of a method, a single function would have its this bound to the relevant class instance.

And my habit of always spelling it that way came out of people asking questions an omitting the fact that the code in question was actually in that context. (Probably helped by the scoping rules for timeline code…)


_level0 FTW!