Open knutkj opened 10 years ago
You asked:
What should happen if a module definition lists the "exports" dependency, and at the same time its factory function returns a value?
Answered here:
If the factory function returns a value (an object, function, or any value that coerces to true), then that value should be assigned as the exported value for the module.
This means the exports module will be ignored.
AMD has a priority for the different exports variations (low - high):
exports
will be exportedmodule.exports
will be exported, note that module.exports and exports are the same object if module.exports is not reassigned within the factoryThe modules ["require", "exports", "module"] are based on the CommonJS modules specification.
Example of CommonJS module:
var foo = require("foo"),
bar = require("bar");
exports.foo = foo;
exports.bar = bar;
Convert it to AMD:
define(["require", "exports", "module", "foo", "bar"], function (require, exports, module) {
var foo = require("foo"),
bar = require("bar");
exports.foo = foo;
exports.bar = bar;
});
I think that the "dependencies" section is missing some details. What is special with the dependency name "exports"? What should happen if a module definition lists the "exports" dependency, and at the same time its factory function returns a value? Here is an example of that behavior:
https://github.com/Reactive-Extensions/RxJS-DOM/blob/921c35a28265466cda7fc2dcdbacfe688efcd456/rx.dom.js#L25
Should the return value of the factory function be used in this case, or should you save the "exports" object as the module value?