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

Axel Rauschmayer axel at rauschma.de
Tue Mar 19 18:45:20 PDT 2013


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


-- 
Dr. Axel Rauschmayer
axel at rauschma.de

home: rauschma.de
twitter: twitter.com/rauschma
blog: 2ality.com

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20130320/ac30ba55/attachment-0001.html>


More information about the es-discuss mailing list