Yeah, sorry, that example went through several iterations as the modules 
proposal evolved, and now it's kind of muddled. I'll update it tomorrow.

Since the reference to the module is used in an expression, it could 
technically be thought of as reflecting the module as an object and pulling out 
its property. But the system is designed so that such uses can be guaranteed to 
have the same performance as if "sum" and "pi" were explicitly imported. I'll 
clarify that example and add another example that's truly dynamic, such as:

    function inspect(m) {
        for (key in m) {
            if (m.hasOwnProperty(key))
                alert("found export: " + key);
        }
    }
    inspect(Math);

Dave

On May 16, 2010, at 10:31 PM, Kevin Curtis wrote:

> On Mon, May 17, 2010 at 6:02 AM, David Herman <[email protected]> wrote:
>> This was the point I was explaining here:
>> 
>>    https://mail.mozilla.org/pipermail/es-discuss/2010-May/011162.html
>> 
>> Modules are static entities, whose structure is known at compile-time. The 
>> "module" form creates these static bindings. But they can be reflected as 
>> first-class values. (Similar to e.g. classes in Java and proposed ES4.)
>> 
>> The "import" form, like "var" and "const" and "function" creates a binding 
>> to a first-class value, whereas the "module" form creates a static module 
>> binding.
>> 
>> So when you write:
>> 
>>    var x = Math;
>> 
>> you create a variable binding to the reflected first-class module value. 
>> Whereas when you write:
>> 
>>    module x = Math;
>> 
>> you are creating a static module binding x which is bound to the static 
>> module bound to Math.
>> 
> 
> 
> OK. On the simple_modules_examples wiki page:
> 
> Reflecting module instances as first-class objects
> 
> <script type="harmony">
> // a static module reference
> module M = Math;
> 
> // reify M as an immutable "module instance object"
> alert("2π = " + M.sum(M.pi, M.pi));
> </script>
> 
> Q: Why does referencing the module M's functions/constants - M.sum and
> M.pi - 'reify' M as an object.(Is this the same process as generating
> a 'reflected first-class module value'?)
> 
> I get the difference between lexical/source vs first class - but this
> comment 'reify' genuinely confuses me. Why isn't the call to M.sum()
> static - known at compile time.
> 
> --

_______________________________________________
es-discuss mailing list
[email protected]
https://mail.mozilla.org/listinfo/es-discuss

Reply via email to