`this` if the global object is not in the scope chain?

# Axel Rauschmayer (13 years ago)

Is this undefined in that case?

# Domenic Denicola (13 years ago)

Such a situation should only be possible within modules (via a custom loader), from my understanding. In which case you're going to be in strict mode anyway, so yes, it's definitely undefined.

# Sam Tobin-Hochstadt (13 years ago)

On Tue, Mar 19, 2013 at 9:25 PM, Axel Rauschmayer <axel at rauschma.de> wrote:

Is this undefined in that case?

I think you may be thinking of the case where a module loader has been configured to omit the global object. This isn't quite how it would work -- instead, the module loader is configured to have a global of the module loader creator's choosing, which could be Object.create(null), for example.

# Axel Rauschmayer (13 years ago)

On Mar 20, 2013, at 2:34 , Sam Tobin-Hochstadt <samth at ccs.neu.edu> wrote:

On Tue, Mar 19, 2013 at 9:25 PM, Axel Rauschmayer <axel at rauschma.de> wrote:

Is this undefined in that case?

I think you may be thinking of the case where a module loader has been configured to omit the global object.

Yes I am.

This isn't quite how it would work -- instead, the module loader is configured to have a global of the module loader creator's choosing, which could be Object.create(null), for example.

Ah, OK. So there will be an object in the scope chain? Or can it be null, too?

But Domenic has made a good point: You can do the following in scripts.

<script>
'use strict';
console.log(this === window); // true
</script>

But in modules, you are never in global scope and always in strict mode. Hence, I don’t see a way to access the global object in the above manner (or in any other manner, unless it refers to itself).

Axel

# Kevin Smith (13 years ago)

But in modules, you are never in global scope and always in strict mode. Hence, I don’t see a way to access the global object in the above manner (or in any other manner, unless it refers to itself).

|this| in a module still refers the the "global" object, whatever that may be in the context of the current loader. It could be window, or not.

# Axel Rauschmayer (13 years ago)

Right, my bad. You could do:

export let foo = this;

or export let bar = doSomethingWithThis(this);