http://stackoverflow.com/questions/7137397/module-exports-vs-exports-in-node-js
其中推荐回答:
http://www.hacksparrow.com/node-js-exports-vs-module-exports.html
module.exports
is the real deal. exports
is just module.exports
's little helper. Your module returns module.exports
to the caller ultimately, not exports
. All exports
does is collect properties and attach them to module.exports
IF module.exports
doesn't have something on it already. If there's something attached to module.exports
already, everything on exports
is ignored.
exports只是作为helper,exports做的仅仅是收集module.exports所没有的属性并把它们挂在到module.exports上,如果module.exports已有某属性,exports的该属性会被直接忽略。
As long are you don't overwrite the module.exports
object with an assignment operation, anything attached to module.exports
and exports
will be available in the 'required' module.
只要你不用赋值符号(=)重写module.exports
对象,任何挂在到module.exports
and export的属性在required的模块里都是可用的。