javascript - 关于underscore源码的一点小疑问
本文介绍了javascript - 关于underscore源码的一点小疑问的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
问 题
在源码中有这样一段:
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
// 整体导出
module.exports = {name:'wason',age:24,sex:'male'};
//单个导出
exports.name = 'wason';
exports.age = 24;
exports.sex = 'male';
这篇关于javascript - 关于underscore源码的一点小疑问的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文