`this` inside modules

Andrea Giammarchi andrea.giammarchi at gmail.com
Mon Jun 9 17:26:49 PDT 2014

once again, in node.js `this` is the exported module. I think we should not
make it `undefined` neither a `global` pointer ... in node.js `this` in
modules is never global except when you launch the console so only in the
main, where we are already consistently good on browsers since `this` is
the global there (script on a page, not modules)

Do we really want to break interoperability with node.js when it comes to
`this` inside modules which is a keyword that could not even be reassigned
to nothing and/or monkey patched ?

As tweeted earlier today: I can already smell the next stinking module
feature detection `if (this) console.log("you are in nodejs") else
alert("WTF browser module")`

Best Regards

On Mon, Jun 9, 2014 at 4:14 PM, Kevin Smith <zenparsing at gmail.com> wrote:

> What is an arrow function bound to in a module?
>> ```js
>> export var a = () => this;
>> ```
> As with all arrow functions, `this` is lexically bound, so it will bind to
> whatever `this` is bound to within the module.  Which is kinda the question
> at hand.
> _______________________________________________
> es-discuss mailing list
> es-discuss at mozilla.org
> https://mail.mozilla.org/listinfo/es-discuss
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20140609/e8b3a261/attachment.html>

More information about the es-discuss mailing list