Value of 'this' in modules

27 views
Skip to first unread message

Jared Siirila

unread,
Jul 28, 2016, 8:15:20 AM7/28/16
to Exploring ES6
I was going through the chapter on modules and got confused on what the value for 'this' would be within a module. Based on the table in 16.6.1 it looked like the value would be undefined, but then in the example provided in 16.6.1.2 there is a comment that // `this` still refers to the global object.

I have tested this behavior with webpack, which I don't think is a perfect comparison, and I see 'this' being undefined. I also tried to run the <script type="module"> element directly within Chrome and Firefox, but as expected it didn't look like it ran since I don't believe a browser has native support for modules yet.

Searching around for a definitive answer online on what 'this' is set to didn't give me great results. I did see a lot of discussion in the es-discuss list on what the value should be, but not a definitive answer.

Axel Rauschmayer

unread,
Oct 31, 2016, 2:10:47 PM10/31/16
to Exploring ES6
It’ll be undefined. That’s a typo that is on my list of things to fix.
Reply all
Reply to author
Forward
0 new messages