Maybe I was over-thinking this problem: I was wondering how to access
module-global data if "this" is shaded. It seemed similar to the "var self =
this" work-around when using non-methods inside methods (forEach() etc.).
module Foo {
var bar = "abc"; // like a global inside this module, right?
export var Baz = {
amethod: {
// how to access bar here? As a global? "this" won't work.
}
}
}
This would become more complicated with nested modules.
On Apr 6, 2011, at 17:20 , David Herman wrote:
>> - Does it ever make sense to access globals via "this"? If so, I assume
>> there will be a use case in the upcoming modules rationale document.
>
> Reflecting the globals via |this| preserves some web compatibility with
> programs that dynamically test the global object. It allows you some
> lightweight reflection of the global scope, while removing some of the more
> problematic reflection of legacy JS (such as deleting globals). For example,
> you can dynamically detect whether a variable is bound.
>
>> - Should there be a keyword for "the current module" (a module-this, if you
>> will)? Accessing module-global data via "this" feels strange (I that is
>> indeed the intention of what I have read). It would also not work inside
>> methods.
>
> I don't know why it feels strange to you; it feels pretty natural to me.
> Banning |this| in certain contexts has never been done in JS and I don't want
> to start doing it. If we don't ban it, it has to have some binding. Binding
> it to null or undefined would also be draconian.
>
> When modules are reflected as first-class values, they are represented as
> objects. The body of a module acts as the object's constructor. Binding the
> module object as |this| fits naturally with the design.
>
>> But it seems like the only globals inside a module are module-relative. Then
>> everything would work out fine.
>
> I don't understand this comment.
>
> Dave
>
>
--
Dr. Axel Rauschmayer
[email protected]
twitter.com/rauschma
home: rauschma.de
blog: 2ality.com
_______________________________________________
es-discuss mailing list
[email protected]
https://mail.mozilla.org/listinfo/es-discuss