以下是源码信息
// Export the Underscore object for **Node.js**, with
// backwards-compatibility for their old module API. If we're in
// the browser, add `_` as a global object.
// (`nodeType` is checked to ensure that `module`
// and `exports` are not HTML elements.)
if (typeof exports != 'undefined' && !exports.nodeType) {
if (typeof module != 'undefined' && !module.nodeType && module.exports) {
exports = module.exports = _;
}
exports._ = _;
} else {
root._ = _;
}
这段代码应该是针对在nodejs环境中将_
的方法挂载到exports._
上,但不太懂这段代码具体逻辑:
typeof exports != 'undefined' && !exports.nodeType
为什么不使用严格不等于!==
或直接用隐式转换exports && !exports.nodeType
;exports.nodeType
和module.nodeType
是什么?;exports = module.exports = _;
这行代码如何理解?。
其实上面的英文注释已经解释了许多
这段代码是用于在nodejs环境中暴露
_
方法