ModuleImport

Kevin Smith zenparsing at gmail.com
Tue Jul 1 11:18:10 PDT 2014


>     module name from './path'
>     ...
>     name.method();
>

Right - that would work for objects-as-modules, but this wouldn't:

    import { something } from "./path";

Unless you somehow emitted getters for all references to "something".
 Without consulting documentation, I would expect that these two things:

    module x from "./path";
        // From within some function or other
        x.foo();

    import { foo } from "./path";
        // From within some function or other
        foo();

would be equivalent.  I think a beginner would find a difference there
surprising.

Also, consider hoisting.

    // Call an imported function directly
    import { foo } from "./path";
    foo(123);

    module m from "./path";
    m.foo();

With "object-as-module", neither one is going to work if you have a
circular dependency at play.

Of course, these gains aren't giant - they support edge cases.  But they
are real.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20140701/e770ab93/attachment-0001.html>


More information about the es-discuss mailing list