cleidigh / ThunderKdB

Thunderbird Addon Code Knowledge Base
11 stars 7 forks source link

When should I use globalThis rather than window? #44

Open eyalroz opened 1 year ago

eyalroz commented 1 year ago

In browser JS code, a "global" variable is actually (always? usually?) a member of the window object. We also see the window object used in Thunderbird, but there is also an object named globalThis. For example, the Services object is a member of globalThis.

When, if at all, should we use globalThis? And which variables should be made members of globalThis rather than of window (assuming they're not local, which they should be of course if one can manage it).