Talk:Modules/1.1
setExports function discussion: http://groups.google.com/group/commonjs/browse_thread/thread/11c6f25c46b3837b
Namespaces proposal
The current specification makes it hard for modules to share or extend common namespace. This is handled much better e.g. in Google Closure Library, although at cost of using global object.
Therefore I propose the extension to the Modules standard in the form of optional second parameter of require function with the meaning of namespace object to be extended by required module, thus to be exposed to required module as exports objects, e.g.:
//modA exports.f1 = function() {}; //modB exports.f2 = function() {}; //main var namaspace1 = {}; require('modA', namespace1); require('modB', namespace1); namespace1.f1(); namespace1.f2();
This could be beneficial especially for modules using submodules, e.g.:
//module exports.f1 = function() {}; require('submodule1', exports); require('submodule2', exports); //main var module = require('module');
Exporting objects by modules could be more flexible if exporting would have been defined in terms of export function and not the exports object.