Closed annevk closed 8 years ago
I'm not sure what you're asking here - are you specifically asking about the identifier global
? Or are you asking about the entire concept of the proposal?
Whether it's a proxy or not is irrelevant to its usefulness - the goal is to have a consistent identifier mandated by the spec to provide what Function('return this')()
returns in every engine, but without the burden of eval.
Doesn't that return undefined in strict mode?
Anyway, this was mostly about the name. (I'm still a big fan of self
personally, but I guess that's "browser-centric" reasoning.)
No, because that function is evaluated in sloppy mode - ie, (function () { 'use strict'; return Function('return this')(); }())
works fine.
As for the name, global
is used in lots of code used on the web to detect that the environment is node
- as is window
to detect browsers, and self
is both part of what's used to detect web workers, and it would cause issues with the very common var self = this
pattern. All three of those names are nonstarters for this reason, as well as @erights being staunchly against anything that isn't a property on an object, for SES reasons, so any bare identifier is out.
Huh? self is not used to detect web workers. self === window too.
You still haven't explained why global is a good name despite it not pointing to the global in the majority of code.
My understanding is that self !== window
in web workers, which don't have window
.
System.global
points to the object on which global variables have properties created, for example, as well as containing Array
, Math
, etc. Properties installed upon it become global variables. Can you explain how this object will be observably different from the global object? Also, in browsers where there's a WindowProxy, is there any possible way to get access to the actual global object? (If not, then the global proxy IS the global object for all intents and purposes)
You can't access the actual global object, but you can observe the difference through variable declarations, navigation, etc. I don't really have a simple example handy, but you can certainly tell that the proxy is not the actual global object (otherwise it could just be the global object of course).
In environments where the proxy is provided, however, that is effectively the same thing as the global object, and the "real" global object is unreachable. Hopefully https://github.com/tc39/proposal-global#html-and-the-windowproxy covers this point?
Kinda, it doesn't really drive home the fact that the Window object is the global object for ECMAScript purposes (in terms of property lookup and such), and WindowProxy is just what everything, including this, returns.
Which is what I wanted to raise. That the conceptual global object is not returned and that therefore this might be a misleading name if you care about being technically correct.
I'll leave this open for a bit and if I have the opportunity, I will ask the room, but the consensus from November was that "global" is appropriate and that the ES spec should pretend like the WindowProxy does not exist (except to make sure that it doesn't accidentally make it's existence a spec violation).
The ES spec does not pretend that. It specifically introduced [[GlobalThisValue]] for it.
ok - is the implication that System.globalThisValue
would be a better name for the property?
A few of the members (some of which are involved in HTML specs) were quite vocal in preferring the bare identifier global
before we were sure it was impossible, so I'm pretty confident that global
is considered to be an acceptable name.
There's no implication, simply trying to make sure the decision is informed.
Gotcha - I'm firmly of the belief that virtually all users don't know or care about the difference between "the global object" and "a proxy to the global object", and that anything other than the name "global" will cause more confusion than it will solve.
That said I will definitely get opinions of others on the committee before closing this :-)
I discussed this with @bterlson and others, and the consensus is that this name is indeed appropriate.
Since for the majority of JavaScript code it's not the global. It's an observable proxy to one.