在源码中有这样一段:
if (typeof exports !== 'undefined') {
if (typeof module !== 'undefined' && module.exports) {
exports = module.exports = _;
}
exports._ = _; // 要么是exports._ = _,要么是module.exports = _
} else {
root._ = _;
}
我的疑问是exports和module.exports任意用一个就行了,这两个不会有循环引用的问题么?
module.exports
和exports
的用途是不一样的,具体表现为如果输出的对象是一个整体对象我们使用module.exports
,如果是对象中的属性单个导出则使用exports