`import` and aliasing bindings

David Herman dherman at mozilla.com
Fri Dec 28 09:28:27 PST 2012


On Dec 28, 2012, at 9:16 AM, Domenic Denicola <domenic at domenicdenicola.com> wrote:

>> The aliasing isn't observable for immutable bindings, only for mutable ones. In my experience, all of the module exports I've seen from NPM modules I've used were immutable.
> 
> This is amusingly tied to the single-export question. I.e. `module.exports =` produces a single immutable export (with mutable properties, see e.g. http://npm.im/glob), but all `exports.foo =` exports are mutable. Nobody does `Object.defineProperty(exports, "foo"', ...)` really. So most exports in npm are immutable… but maybe not for the reason you'd expect.

Doesn't matter what the reasons are, though; the point is that this isn't going to break existing patterns. Whereas if you don't alias, then you will cause code to break when it does expect it. Another example where this could come up is initialization. Since imports tend to be at the beginning of a module, you could end up reading the value of a not-yet-initialized variable too soon.

Dave



More information about the es-discuss mailing list