Why globalThis instead of something intuitive like globalObject, systemGlobal, or globalEntity?

#!/JoePea joe at trusktr.io
Fri Oct 4 18:39:22 UTC 2019


> but the global `this` you captured still has the same identity as the new reference.

Interesting, I never knew that. Do you have a code sample to show how
to detect or prove that?

On Sat, Sep 21, 2019 at 9:05 PM Isiah Meadows <isiahmeadows at gmail.com> wrote:
>
> If you look in the proposal's repo, they explain the rationale behind the identifier:
> https://github.com/tc39/proposal-global/
>
> Here's a short summary: `globalThis` is the same value you get from evaluating `this` in the global scope of a sloppy mode script. This is subtly different than a "global object", which JS has no concept of. There's other nuances involved, too.
>
> Concretely, for one example, `globalObject` was explicitly rejected because in HTML, the global `this` is a proxy of `window`, not the `window` object itself. The `window` proxy delegates all operations to the current global `window`, as you might expect. But here's where things get interesting: during navigation, the window changes, yet the global `this` does not, so if you define a property, capture the global `this`, and navigate, the property you just defined will disappear, but the global `this` you captured still has the same identity as the new reference.
>
> This file in particular explains the naming side of it in detail:
> https://github.com/tc39/proposal-global/blob/master/NAMING.md It covers the other suggested names here indirectly.
>
> And do keep in mind much of TC39's members are non-native speakers themselves, including one of the proposal's biggest champions/fans, Matthias. So it's not like that concern goes unnoticed - if anything, it gets accounted for without them even thinking about it. It might also explain why it's `array.entries()`, `map.entries()`, and similar when the more proper English name would've been `array.pairs()`, `map.pairs()`, and so on: entries are really what values from `value[Symbol.iterator]()` represent, and non-native speakers sometimes misuse "entries" as if it were synonymous with "pairs". Contrast this with Underscore's `_.pairs`, named by a native English speaker back in 2012, long before ES6 was a thing, and it stood as precedent for having `coll.entries()` for various collections.
>
> On Sat, Sep 21, 2019 at 14:12 #!/JoePea <joe at trusktr.io> wrote:
>>
>> I know it may be too late for this, but I imagine `globalThis` can bring confusion to beginners, especially ESL beginners.
>>
>> Things like `globalObject`, `systemGlobal`, or `globalEntity` would've been more intuitive; they make sense in plain English.
>>
>> Well anyways, have a good weekend!
>>
>> - Joe
>>
>>
>> _______________________________________________
>> es-discuss mailing list
>> es-discuss at mozilla.org
>> https://mail.mozilla.org/listinfo/es-discuss


More information about the es-discuss mailing list