JavaScript's global object is now "globalThis"


#1

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


#2

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?


#3

I see it in Canary

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

image


#4

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

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

#5

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


#6

Were both functions needed?


#7

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…)


#8

_level0 FTW!