On Mar 22, 2012, at 4:55 AM, Andreas Rossberg wrote:
> One point that I haven't seen mentioned yet (and it is unrelated to syntax):
> "export call" makes me cringe -- making modules callable is not just weird,
> it seems completely future-hostile to the possibility of having parameterized
> modules. I don't think it is worth bending the notion of module like that if
> all that is gained is minor convenience.
Making modules callable has serious semantic warts as well. In order to support
static binding, we have to ensure that the properties of a module instance
object are statically known, which means that there can't be a mutable
prototype in the prototype chain. But to support the expected
.bind/.call/.apply methods of functions, that means we have to a) pollute
callable modules with these extra inherited properties and b) freeze the
prototype. This is all pretty ad hoc and unsatisfying.
I would also be in favor of holding the line against callable modules, but a
number of people have stated that they consider them very important. One of the
going examples has been jQuery, where you would say:
// jquery.js
export call(selector) { ... }
...
// client
import "jquery.js" as $; /*OR*/ module $ = "jquery.js" /*OR*/ module $ at
"jquery.js" /*OR*/ import $ at "jquery.js"
let elements = ["foo", "bar", "baz"].map($); // implicitly calls .call
$("quux").style(...);
That said, it requires no more code to say:
// jquery.js
export function $(selector) { ... }
...
// client
import $ from "jquery.js";
let elements = ["foo", "bar", "baz"].map($);
$("quux").style(...);
So maybe people have over-sold the importance of callable modules. In CommonJS
+ ES5, it's convenient because there's no way to avoid binding a name to the
module. Whereas if you have destructuring and destructuring import, a module
with a single export does not need to be any less convenient than a module that
is itself the single export.
Thoughts?
Dave
_______________________________________________
es-discuss mailing list
[email protected]
https://mail.mozilla.org/listinfo/es-discuss