`this` inside modules
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")`
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?
>> 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
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the es-discuss