tc39 / proposal-global

ECMAScript Proposal, specs, and reference implementation for `global`
http://tc39.github.io/proposal-global/
MIT License
349 stars 18 forks source link

Support `global` as alias of `globalThis` where possible #36

Closed ExE-Boss closed 5 years ago

ExE-Boss commented 5 years ago

The main reasoning is that this is very confusing in the context of JavaScript due to it being a horrible mess that was originally created by a single developer for Netscape Navigator.

See also https://github.com/tc39/proposal-global/issues/31 for more reasoning.

(I really, really hate the name globalThis, even more than using window and I much prefer the technological purity of plain global)

At the very least, I would want global to be supported in modules by default.


Because of the above, I tend to do:

if (!("global" in window) || global !== window) {
    Object.defineProperty(window, "global", {
        get() {
            return window;
        }
    });
}

Then, I just use global as alias of window.

ljharb commented 5 years ago

Thanks for your feedback!

global is not web-compatible, in Scripts or Modules, because it's used as environment detection (to distinguish node and browsers). Please see the list of constraints for more information: https://github.com/tc39/proposal-global/blob/master/NAMING.md

ExE-Boss commented 5 years ago

I still prefer, and will keep using, global over globalThis.