The exports
and module.exports
globals aren't as interchangeable as documented
#5228
Comments
what's basically happening is: var module = {
exports: {}
}
;(function myFile(module, exports) {
exports = 'something'
})(module, module.exports)
module.exports === {} so simply setting sure, docs on this would be helpful, but nothing has to change. http://nodejs.org/api/modules.html#modules_module_exports doesn't really explain this. |
@jonathanong that's a better way of explaining what I meant, thanks. I found this because it bit me in the butt earlier today when I refactored a module to export a single constructor and everything blew up. It was relatively easy to find the root of the problem once I realized the docs were.. incomplete. It's the requirement that |
The docs are probably the easiest thing to get an accepted pull request for - go for it! |
I've got a branch for it. Submitting a pull request for stable shortly.. |
My commits went in (93391ae and 1deeab2), so this can probably be closed. Not sure if closing is best done by submitters or bug wranglers. I'll close in a couple days if I see no responses. I noticed a couple other weirdnesses in the docs, but a new issue will be created for them when I submit a pull request. |
Thanks for following up, if you know your issue has been fixed or no longer valid, feel free to close -- but just make sure to include your reasons for closing, the perfect example is the fact that you included the commits your fixes landed in. |
According to the docs,
exports
is a global-like alias formodule.exports
, but in practice they are not interchangeable. It doesn't take much thinking to see why that is the case (exports
no longer referencesmodule.exports
if you re-assign it).Examples:
pluseone.js
plustwo.js
plusthree.js
plusfour.js
REPL (v0.10.3)
I think either the docs need touching up, or there needs to be some hoop jumping added to handle the
exports = Constructor
shorthand. Maybeexports
should be removed from the docs entirely to discourage use?The text was updated successfully, but these errors were encountered: